package com.ruoyi.statisticalCenter.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.common.utils.GetDateStringUtils;
import com.ruoyi.hqfinance.domain.HqClientRelation;
import com.ruoyi.hqfinance.domain.HqExportInfo;
import com.ruoyi.hqfinance.domain.HqNetworkBillDetail;
import com.ruoyi.hqfinance.mapper.HqClientRelationMapper;
import com.ruoyi.hqfinance.mapper.HqExportInfoMapper;
import com.ruoyi.hqfinance.mapper.HqNetworkBillDetailMapper;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.ScOutReturnSheetDetail;
import com.ruoyi.logistic.domain.ScOutReturnSheetDetailVo;
import com.ruoyi.logistic.mapper.ScOutReturnSheetDetailMapper;
import com.ruoyi.qualityControl.domain.ScOutBoundSendSheet;
import com.ruoyi.statisticalCenter.domain.*;
import com.ruoyi.statisticalCenter.domain.vo.DateStrVo;
import com.ruoyi.statisticalCenter.domain.vo.ScOutReturnSheetChildVo;
import com.ruoyi.statisticalCenter.domain.vo.ScOutReturnSheetPointVo;
import com.ruoyi.statisticalCenter.domain.vo.ScOutReturnSheetVo;
import com.ruoyi.statisticalCenter.enums.ScOutBoundReturnSheetSetEnum;
import com.ruoyi.statisticalCenter.mapper.*;
import com.ruoyi.statisticalCenter.service.ScOutReturnSheetService;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ScOutReturnSheetServiceImpl implements ScOutReturnSheetService {
    @Autowired
    private ScOutReturnSheetMapper scOutReturnSheetMapper;
    @Autowired
    private ScOutBoundReturnSheetSetMapper scOutBoundReturnSheetSetMapper;
    @Autowired
    private TableService tableService;
    @Autowired
    private ScOutboundEliminateMapper eliminateMapper;
    @Autowired
    private HqNetworkBillDetailMapper hqNetworkBillDetailMapper;
    @Autowired
    private ScOutReturnSheetClientMapper scOutReturnSheetClientMapper;
    @Autowired
    private ScOutBoundSendSheetMapper scOutBoundSendSheetMapper;

    @Autowired
    private HqExportInfoMapper hqExportInfoMapper;

    @Autowired
    private ScOutReturnSheetDetailMapper detailMapper;

    @Autowired
    private HqClientRelationMapper hqClientRelationMapper;

    MathContext mc = new MathContext(3, RoundingMode.HALF_UP); // 设置精度为3位，采用四舍五入模式


    @Override
    public R collect(ScOutReturnSheetVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<ScOutReturnSheet> collect = collectExport(vo);
        for (ScOutReturnSheet scOutReturnSheet : collect) {
            scOutReturnSheet.setDate(vo.getStartTime() + "至" + vo.getEndTime());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", PageInfo.info(collect));
        jsonObject.put("fields", getTableVo());

        if (collect == null || collect.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }

    @Override
    public R collectCache(ScOutReturnSheetVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<ScOutReturnSheetDetailVo> collect = detailMapper.selectList(vo);
        if (collect == null || collect.size() == 0) {
            return R.fail("暂无数据");
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        int dateDifference = 1;
        try {
            Date d1 = sdf.parse(vo.getStartTime());
            Date d2 = sdf.parse(vo.getEndTime());

            // 获取日历实例
            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(d1);
            cal2.setTime(d2);

            // 计算日期差
            long diffInMillis = Math.abs(cal2.getTimeInMillis() - cal1.getTimeInMillis());
            long diffInDays = diffInMillis / (24 * 60 * 60 * 1000);
            dateDifference = (int) (dateDifference + diffInDays);
            System.out.println("日期差为： " + diffInDays + " 天");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (ScOutReturnSheetDetailVo scOutReturnSheetDetail : collect) {
            if (dateDifference > 1) {
                scOutReturnSheetDetail.setHasChildren(true);
            }
            scOutReturnSheetDetail.setDate(vo.getStartTime() + "至" + vo.getEndTime());
            //缓存表设置增量返利0~1kg符合政策票数
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount() != null) {
                int incrementalRebate0To1KgPolicyCompliantTickets = scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount()
                        - scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
                        - scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets() - scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis();
                scOutReturnSheetDetail.setIncrementalRebate0To1KgPolicyCompliantTickets(incrementalRebate0To1KgPolicyCompliantTickets);
            }
            // 0-1阶梯考核
            //考核业务量
            Integer tieredAssessment0To1KgInsufficientVolume = scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume() - scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount();
            if (tieredAssessment0To1KgInsufficientVolume < 0) {
                scOutReturnSheetDetail.setTieredAssessment0To1KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setTieredAssessment0To1KgInsufficientVolume(0);
            }
            //0-999业务考核
            //不足业务量
            Integer businessAssessment0To999KgInsufficientVolume = scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume() - scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount();
            if (businessAssessment0To999KgInsufficientVolume < 0) {
                scOutReturnSheetDetail.setBusinessAssessment0To999KgInsufficientVolume(0);
                scOutReturnSheetDetail.setBusinessAssessment0To999KgAmount(new BigDecimal(0));
            }
//            if (vo.getNetworkLevel() == 2) {
//                List<ScOutReturnSheetDetail> children = scOutReturnSheetDetail.getChildren();
//                for (ScOutReturnSheetDetail child : children) {
//                    String name = child.getName();
//                    vo.setParentName(name);
//                    vo.setStartTime(child.getDate());
//                    vo.setEndTime(child.getDate());
//                    List<ScOutReturnSheetDetail> detailList = detailMapper.selectChildList(vo);
//                    child.setChildren(detailList);
//                }
//            }
            //增量返利0-1kg-金额
            int incrementalRebate0To1KgShipmentCount = 0;
            int incrementalRebate0To1KgDailyBasis = 0;
            int incrementalRebate0To1KgExcludeTickets = 0;
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount() != null) {
                incrementalRebate0To1KgShipmentCount = scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount();
            }
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis() != null) {
                incrementalRebate0To1KgDailyBasis = scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis();
            }
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets() != null) {
                incrementalRebate0To1KgExcludeTickets = scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets();
            }
            int IncrementalRebate0To1KgPolicyCompliantTickets = incrementalRebate0To1KgShipmentCount - incrementalRebate0To1KgDailyBasis * dateDifference - incrementalRebate0To1KgExcludeTickets;
            scOutReturnSheetDetail.setIncrementalRebate0To1KgPolicyCompliantTickets(IncrementalRebate0To1KgPolicyCompliantTickets);
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgRebateStandard() != null) {
                scOutReturnSheetDetail.setIncrementalRebate0To1KgAmount(new BigDecimal(IncrementalRebate0To1KgPolicyCompliantTickets).multiply(scOutReturnSheetDetail.getIncrementalRebate0To1KgRebateStandard()).setScale(2, RoundingMode.HALF_UP));
            }
            //0-1kg阶梯考核-考核业务
            int tieredAssessment0To1KgAssessedVolume = 0, tieredAssessment0To1KgShipmentCount = 0;
            if (scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume() != null) {
                tieredAssessment0To1KgAssessedVolume = scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume();
            }
            if (scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount() != null) {
                tieredAssessment0To1KgShipmentCount = scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount();
            }
            if (tieredAssessment0To1KgShipmentCount > tieredAssessment0To1KgAssessedVolume) {
                scOutReturnSheetDetail.setTieredAssessment0To1KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setTieredAssessment0To1KgInsufficientVolume(0);
            }
            //0-999业务考核
            int businessAssessment0To999KgAssessedVolume = 0, businessAssessment0To999KgShipmentCount = 0;
            if (scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume() != null) {
                businessAssessment0To999KgAssessedVolume = scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume();
            }
            if (scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount() != null) {
                businessAssessment0To999KgShipmentCount = scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount();
            }
            if (businessAssessment0To999KgShipmentCount > businessAssessment0To999KgAssessedVolume) {
                scOutReturnSheetDetail.setBusinessAssessment0To999KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setBusinessAssessment0To999KgInsufficientVolume(0);
            }
            scOutReturnSheetDetail.setOneToThreeKgRebateRebateVolume(scOutReturnSheetDetail.getOneToThreeKgRebateRebateVolumeReceipt());
            scOutReturnSheetDetail.setOneToThreeKgRebateRebateStandard(scOutReturnSheetDetail.getOneToThreeKgRebateRebateStandardReceipt());
            scOutReturnSheetDetail.setOneToThreeKgRebateRebate(scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt());
            if (scOutReturnSheetDetail.getTieredAssessment0To1KgAmount() ==  null){
                scOutReturnSheetDetail.setTieredAssessment0To1KgAmount(new BigDecimal(0));
            }
            BigDecimal add = scOutReturnSheetDetail.getZeroToHalfKgAmount()
                    .add(scOutReturnSheetDetail.getHalfTo1KgAmount()
                            .add(scOutReturnSheetDetail.getOneTo3KgAmount()
                                    .add(scOutReturnSheetDetail.getThreeToTenKgAmount()
                                            .add(scOutReturnSheetDetail.getTenTo399KgAmount()
                                                    .add(scOutReturnSheetDetail.getXoverlayPolicyOneTo3KgAmount()
                                                            .add(scOutReturnSheetDetail.getIncrementalRebate0To1KgAmount()
                                                                    .add(scOutReturnSheetDetail.getCumulativeRebate0To2KgAmount()
                                                                            .add(scOutReturnSheetDetail.getTieredAssessment0To1KgAmount()
                                                                                    .add(scOutReturnSheetDetail.getBusinessAssessment0To999KgAmount())))))))));

            scOutReturnSheetDetail.setTotalRebateAmount(add);

            //总部净返利合计
            BigDecimal headquartersNetRebateTotal = new BigDecimal(0.00);
            if (scOutReturnSheetDetail.getTotalRebateAmount() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getTotalRebateAmount());
            }
            if (scOutReturnSheetDetail.getExclusionAdjustment() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getExclusionAdjustment());
            }
            if (scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt());
            }
            scOutReturnSheetDetail.setHeadquartersNetRebateTotal(headquartersNetRebateTotal);
        }

        if (vo.getNetworkLevel() == 0) {
            for (ScOutReturnSheetDetailVo scOutReturnSheetDetail : collect) {
                //3-999分档返利
                scOutReturnSheetDetail.setThreeTo999KgRebatePolicyRebate(scOutReturnSheetDetail.getThreeTo999KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheetDetail.getThreeTo999KgRebatePolicyQualified())));
            }
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", PageInfo.info(collect));
        jsonObject.put("fields", getTableVo());

        if (collect == null || collect.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }


    @Override
    public List<ScOutReturnSheet> collectExport(ScOutReturnSheetVo vo) {
        List<ScOutReturnSheetDetailVo> collectDetail = detailMapper.selectList(vo);
//        collectDetail= null;
        if (collectDetail != null && collectDetail.size() > 0) {
            List<ScOutReturnSheet> collect = new ArrayList<>();
            for (ScOutReturnSheetDetailVo scOutReturnSheetDetail : collectDetail) {
                ScOutReturnSheet scOutReturnSheet = new ScOutReturnSheet();
                BeanUtils.copyProperties(scOutReturnSheetDetail, scOutReturnSheet);
                collect.add(scOutReturnSheet);
            }
            return collect;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        int dateDifference = 1;
        try {
            Date d1 = sdf.parse(vo.getStartTime());
            Date d2 = sdf.parse(vo.getEndTime());

            // 获取日历实例
            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(d1);
            cal2.setTime(d2);

            // 计算日期差
            long diffInMillis = Math.abs(cal2.getTimeInMillis() - cal1.getTimeInMillis());
            long diffInDays = diffInMillis / (24 * 60 * 60 * 1000);
            dateDifference = (int) (dateDifference + diffInDays);
            System.out.println("日期差为： " + diffInDays + " 天");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        PageHelper.startPage(vo.getPageDate());
        List<ScOutReturnSheet> collect = scOutReturnSheetMapper.collect(vo);
        if (vo.getNetworkLevel() == 0) {
            //获取不同标准的剔除票数
            Integer zeroToHalfKgEliminateNum = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 0.0, 0.5);
            Integer halfTo1KgEliminateNum = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 0.5, 1.0);
            Integer oneTo3KgEliminateNum = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
            Integer threeToTenKgEliminateNum = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 3.0, 10.0);
            Integer xoverlayPolicyOneTo3KgPolicyQualified = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
            Integer incrementalRebate0To1KgExcludeTickets = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 0.0, 1.0);
            Integer cumulativeRebate0To2KgExcludeTickets = eliminateMapper.selectByWeightAndDate(vo.getStartTime(), vo.getEndTime(), 0.0, 2.0);
            Integer oneToThreeKgRebateDailyVolumeReceipt = scOutReturnSheetMapper.selectClientOneToThreeDaily();
            PageDate pageDate = vo.getPageDate();
//Integer pageNum = pageDate.getPageNum();
//Integer pageSize = pageDate.getPageSize();
            vo.setNetworkLevel(2);
            pageDate.setPageNum(1);
            pageDate.setPageSize(100000);
            vo.setPageDate(pageDate);
            List<ScOutReturnSheet> scOutReturnSheets = this.collectExport(vo); /*scOutReturnSheetMapper.collect(vo);*/
//pageDate.setPageNum(pageNum);
//pageDate.setPageSize(pageSize);
            vo.setPageDate(pageDate);
            vo.setNetworkLevel(0);

            for (ScOutReturnSheet scOutReturnSheet : collect) {
                //按时间段统计时，设置阶梯考核-日业务量*天数
                scOutReturnSheet.setTieredAssessment0To1KgAssessedVolume(scOutReturnSheet.getTieredAssessment0To1KgDailyVolume() * dateDifference);
                scOutReturnSheet.setBusinessAssessment0To999KgAssessedVolume(scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume() * dateDifference);
                scOutReturnSheet.setThrowawayAssessment0To999KgAssessedVolume(scOutReturnSheet.getThrowawayAssessment0To999KgDailyVolume() * dateDifference);

                //0-0.5kg超基数返利-差额
                Integer zeroToHalfKgExceedBasePolicyDifference = 0;
                //0-0.5kg超基数返利-返利
                BigDecimal zeroToHalfKgExceedBasePolicyRebate = new BigDecimal(0.00);

                //0.5-1kg超基数返利-差额
                Integer halfTo1KgExceedBasePolicyDifference = 0;
                //0.5-1kg超基数返利-返利
                BigDecimal halfTo1KgExceedBasePolicyRebate = new BigDecimal(0.00);

                //应收总部金额-1-3kg一客一价返利-发件数
                Integer oneToThreeKgRebateShipmentCountReceipt = 0;
                //应收总部金额-1-3kg一客一价返利-返利业务量
                Integer oneToThreeKgRebateRebateVolumeReceipt = 0;
                //"应付承包区金额-1-3kg一客一价返利-发件数")
                Integer oneToThreeKgRebateShipmentCount = 0;
                //"应付承包区金额-1-3kg一客一价返利-返利业务量")
                Integer oneToThreeKgRebateRebateVolume = 0;
                //1-3kg分档返利-返利"
                BigDecimal oneTo3KgRebatePolicyRebate = new BigDecimal(0.00);
                //3-999kg分档返利-返利
                BigDecimal threeTo999KgRebatePolicyRebate = new BigDecimal(0.00);
                //1-3kg叠加返利-返利
                BigDecimal oneToThreeKgAdditiveRebate = new BigDecimal(0.00);
                //0-2kg叠加返利-返利"
                BigDecimal zeroToTwoKgAdditiveRebate = new BigDecimal(0.00);
                //"应收总部金额-1-3kg一客一价返利-一客一价金额")
                BigDecimal oneToThreeKgRebateAmountReceipt = new BigDecimal(0.00);
                //"应付承包区金额-1-3kg一客一价返利-返利")
                BigDecimal oneToThreeKgRebateRebate = new BigDecimal(0.00);
                //后加  //在这里计算合计中需要用到的明细总金额
                for (ScOutReturnSheet outReturnSheet : scOutReturnSheets) {
                    System.out.println(outReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());
                    if (outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() != 0) {
                        //应收总部发件数  从承包区中汇总
                        oneToThreeKgRebateShipmentCountReceipt += outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt();
                        //应付承包区发件数
                        oneToThreeKgRebateShipmentCount += outReturnSheet.getOneToThreeKgRebateShipmentCount();
                        //发件数-考核业务量>0，则等于发件量，否则为0值  应收总部
                        if (outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() > outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt()) {
                            oneToThreeKgRebateRebateVolumeReceipt += outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt();
                        }
                        //发件数-考核业务量>0，则等于发件量，否则为0值  应付承包区
                        if (outReturnSheet.getOneToThreeKgRebateShipmentCount() - outReturnSheet.getOneToThreeKgRebateDailyVolume() > 0) {
                            oneToThreeKgRebateRebateVolume += outReturnSheet.getOneToThreeKgRebateShipmentCount();
                        }

                        //发件数-考核业务量>0，则等于发件量，否则为0值
                        if (outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == 0) {
                            outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                        } else {
                            if (outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() - outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() > 0) {
                                outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
                            } else {
                                outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                            }
                        }
                        //一客一价金额 = 发件数*返利标准
                        BigDecimal multiply = outReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().multiply(BigDecimal.valueOf(outReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt()));
                        //应收总部
                        oneToThreeKgRebateAmountReceipt = oneToThreeKgRebateAmountReceipt.add(multiply);
                        //应付承包区金额
                        oneToThreeKgRebateRebate = oneToThreeKgRebateRebate.add(multiply);
                    }
                    //计算0-0.5kg超基数返利-返利票数  符合政策票-基数
                    if (outReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() > outReturnSheet.getZeroToHalfKgExceedBasePolicyBase()) {
                        //差额
                        zeroToHalfKgExceedBasePolicyDifference += outReturnSheet.getZeroToHalfKgExceedBasePolicyQualified();
                        //设置承包区的差额
                        outReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(outReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());
                    } else {
                        outReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
                    }
                    //返利标准不存在或=0  或差额为0  返利为0
                    if (outReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard() == null || outReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().compareTo(BigDecimal.ZERO) == 0 || outReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() == 0) {
                        zeroToHalfKgExceedBasePolicyRebate = zeroToHalfKgExceedBasePolicyRebate.add(BigDecimal.valueOf(0.00));
                    } else {
                        //返利 =  标准 * 差额
                        zeroToHalfKgExceedBasePolicyRebate = zeroToHalfKgExceedBasePolicyRebate.add(outReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(outReturnSheet.getZeroToHalfKgExceedBasePolicyDifference())));
                    }
                    //0.5~1
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(scOutReturnSheet.getHalfTo1KgPolicyQualified());
                    if (outReturnSheet.getHalfTo1KgExceedBasePolicyQualified() > outReturnSheet.getHalfTo1KgExceedBasePolicyBase()) {
                        halfTo1KgExceedBasePolicyDifference += outReturnSheet.getHalfTo1KgExceedBasePolicyQualified();
                        outReturnSheet.setHalfTo1KgExceedBasePolicyDifference(outReturnSheet.getHalfTo1KgExceedBasePolicyQualified());
                    } else {
                        outReturnSheet.setHalfTo1KgExceedBasePolicyDifference(0);
                    }
                    BigDecimal half = outReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard();
                    BigDecimal decimal = BigDecimal.valueOf(outReturnSheet.getHalfTo1KgExceedBasePolicyDifference());
                    BigDecimal multiply = null;
                    if (half == null || half.compareTo(BigDecimal.ZERO) == 0 || decimal == null || decimal.compareTo(BigDecimal.ZERO) == 0) {
                        multiply = BigDecimal.valueOf(0.00);
                    } else {
                        multiply = half.multiply(decimal);
                    }
                    halfTo1KgExceedBasePolicyRebate = halfTo1KgExceedBasePolicyRebate.add(multiply);

                    //1~3
                    if (outReturnSheet.getOneTo3KgRebatePolicyRebateStandard() == null
                            || outReturnSheet.getOneTo3KgRebatePolicyRebateStandard().compareTo(BigDecimal.ZERO) == 0
                            || outReturnSheet.getOneTo3KgRebatePolicyQualified() == null || outReturnSheet.getOneTo3KgRebatePolicyQualified() == 0) {
                        oneTo3KgRebatePolicyRebate = oneTo3KgRebatePolicyRebate.add(BigDecimal.valueOf(0, 00));
                    } else {
                        oneTo3KgRebatePolicyRebate = oneTo3KgRebatePolicyRebate.add(outReturnSheet.getOneTo3KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(outReturnSheet.getOneTo3KgRebatePolicyQualified())));
                    }
                    //3~999
                    if (outReturnSheet.getThreeTo999KgRebatePolicyRebateStandard() == null
                            || outReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().compareTo(BigDecimal.ZERO) == 0
                            || outReturnSheet.getThreeTo999KgRebatePolicyQualified() == null || outReturnSheet.getThreeTo999KgRebatePolicyQualified() == 0) {
                        threeTo999KgRebatePolicyRebate = threeTo999KgRebatePolicyRebate.add(BigDecimal.valueOf(0.00));
                    } else {
                        threeTo999KgRebatePolicyRebate = threeTo999KgRebatePolicyRebate.add(outReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(outReturnSheet.getThreeTo999KgRebatePolicyQualified())));
                    }

                    //叠加返利1~3
                    if (outReturnSheet.getOneToThreeKgAdditiveRebateStandard() == null
                            || outReturnSheet.getOneToThreeKgAdditiveRebateStandard().compareTo(BigDecimal.ZERO) == 0
                            || outReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets() == null || outReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets() == 0) {
                        oneToThreeKgAdditiveRebate = oneToThreeKgAdditiveRebate.add(BigDecimal.valueOf(0, 00));
                    } else {
                        oneToThreeKgAdditiveRebate = oneToThreeKgAdditiveRebate.add(outReturnSheet.getOneToThreeKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(outReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets())));
                    }
                    //0-2kg叠加返利
                    if (outReturnSheet.getZeroToTwoKgAdditiveRebateStandard() == null
                            || outReturnSheet.getZeroToTwoKgAdditiveRebateStandard().compareTo(BigDecimal.ZERO) == 0
                            || outReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets() == null || outReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets() == 0) {
                        zeroToTwoKgAdditiveRebate = zeroToTwoKgAdditiveRebate.add(BigDecimal.valueOf(0.00));
                    } else {
                        zeroToTwoKgAdditiveRebate = zeroToTwoKgAdditiveRebate.add(outReturnSheet.getZeroToTwoKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(outReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets())));
                    }

                }

                //应收总部金额-1-3kg一客一价返利-发件数
                scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(oneToThreeKgRebateShipmentCountReceipt);
                scOutReturnSheet.setOneToThreeKgRebateShipmentCount(oneToThreeKgRebateShipmentCount);

                //0-0.5kg分档返利-剔除票数
                scOutReturnSheet.setZeroToHalfKgEliminateNum(zeroToHalfKgEliminateNum);
                //0-0.5kg分档返利-符合政策票数
                if (scOutReturnSheet.getZeroToHalfKgShipments() == null) {
                    scOutReturnSheet.setZeroToHalfKgShipments(0);
                }
                //符合政策票数 = 发件数 - 剔除票数
                Integer zeroToHalfKgPolicyQualified = scOutReturnSheet.getZeroToHalfKgShipments() - zeroToHalfKgEliminateNum;
                scOutReturnSheet.setZeroToHalfKgPolicyQualified(zeroToHalfKgPolicyQualified);
                //0-0.5kg分档返利-金额 = 标准 * 符合政策票数
                scOutReturnSheet.setZeroToHalfKgAmount(scOutReturnSheet.getZeroToHalfKgRebateStandard().multiply(BigDecimal.valueOf(zeroToHalfKgPolicyQualified)));

                //0.5-1kg分档返利-剔除票数
                scOutReturnSheet.setHalfTo1KgEliminateNum(halfTo1KgEliminateNum);
                //0.5-1kg分档返利-符合政策票数
                Integer halfTo1KgPolicyQualified = scOutReturnSheet.getHalfTo1KgShipments() - halfTo1KgEliminateNum;
                scOutReturnSheet.setHalfTo1KgPolicyQualified(halfTo1KgPolicyQualified);
                //0.5-1kg分档返利-金额
                scOutReturnSheet.setHalfTo1KgAmount(scOutReturnSheet.getHalfTo1KgRebateStandard().multiply(BigDecimal.valueOf(halfTo1KgPolicyQualified)));

                //1-3kg分档返利-剔除票数
                scOutReturnSheet.setOneTo3KgEliminateNum(oneTo3KgEliminateNum);
                //1-3kg分档返利-符合政策票数
                Integer oneTo3KgPolicyQualified = scOutReturnSheet.getOneTo3KgShipments() - oneTo3KgEliminateNum;
                scOutReturnSheet.setOneTo3KgPolicyQualified(oneTo3KgPolicyQualified);
                //1-3kg分档返利-金额
                scOutReturnSheet.setOneTo3KgAmount(scOutReturnSheet.getOneTo3KgRebateStandard().multiply(BigDecimal.valueOf(oneTo3KgPolicyQualified)));

                //3-10kg分档返利-剔除票数
                scOutReturnSheet.setThreeToTenKgEliminateNum(threeToTenKgEliminateNum);
                //3-10kg分档返利-符合政策票数
                Integer threeToTenKgPolicyQualified = scOutReturnSheet.getThreeToTenKgShipments() - threeToTenKgEliminateNum;
                scOutReturnSheet.setThreeToTenKgPolicyQualified(threeToTenKgPolicyQualified);
                //3-10kg分档返利-金额
                scOutReturnSheet.setThreeToTenKgAmount(scOutReturnSheet.getThreeToTenKgRebateStandard().multiply(BigDecimal.valueOf(threeToTenKgPolicyQualified)));

                //叠加返利1-3kg-剔除票数
                scOutReturnSheet.setOneTo3KgRebatePolicyQualified(scOutReturnSheet.getOneTo3KgPolicyQualified());
                scOutReturnSheet.setXoverlayPolicyOneTo3KgPolicyQualified(xoverlayPolicyOneTo3KgPolicyQualified);

                //叠加返利1-3kg-符合政策票数
                if (vo.getStartTime() != null && vo.getEndTime() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() != null && xoverlayPolicyOneTo3KgPolicyQualified != null) {
                    int xoverlayPolicyOneTo3KgRebateStandard = scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments()
                            - scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
                            - xoverlayPolicyOneTo3KgPolicyQualified - scOutReturnSheet.getXoverlayPolicyOneTo3KgBase();

                    // 如果结果小于0，设置为0
                    scOutReturnSheet.setXoverlayPolicyOneTo3KgRebateStandard(Math.max(xoverlayPolicyOneTo3KgRebateStandard, 0));
                }

                //叠加返利1-3kg-金额
                if (scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard() != null) {
                    scOutReturnSheet.setXoverlayPolicyOneTo3KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().multiply(BigDecimal.valueOf(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard())));
                }

                //增量返利0-1kg-剔除票数
                scOutReturnSheet.setIncrementalRebate0To1KgExcludeTickets(incrementalRebate0To1KgExcludeTickets);
                //增量返利0-1kg-符合政策票数
                if (vo.getStartTime() != null && vo.getEndTime() != null) {
                    int incrementalRebate0To1KgPolicyCompliantTickets = scOutReturnSheet.getIncrementalRebate0To1KgShipmentCount()
                            - scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
                            - incrementalRebate0To1KgExcludeTickets - scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis();

                    // 如果结果小于0，设置为0
                    scOutReturnSheet.setIncrementalRebate0To1KgPolicyCompliantTickets(Math.max(incrementalRebate0To1KgPolicyCompliantTickets, 0));
                }
                //叠加返利1-3kg-金额
                if (scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage() != null) {
                    scOutReturnSheet.setIncrementalRebate0To1KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().multiply(BigDecimal.valueOf(scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets())));
                }

                //0-2kg叠加返利-剔除票数
                scOutReturnSheet.setCumulativeRebate0To2KgExcludeTickets(cumulativeRebate0To2KgExcludeTickets);
                //0-2kg叠加返利-符合政策票数
                if (vo.getStartTime() != null && vo.getEndTime() != null) {
                    int cumulativeRebate0To2KgPolicyCompliantTickets = scOutReturnSheet.getCumulativeRebate0To2KgShipmentCount()
                            - scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
                            - cumulativeRebate0To2KgExcludeTickets - scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis();
                    scOutReturnSheet.setCumulativeRebate0To2KgPolicyCompliantTickets(Math.max(cumulativeRebate0To2KgPolicyCompliantTickets, 0));
                }
                //0-2kg叠加返利-金额
                scOutReturnSheet.setCumulativeRebate0To2KgAmount(scOutReturnSheet.getCumulativeRebate0To2KgRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets())));

                // 0-1阶梯考核
                //考核业务量
                Integer tieredAssessment0To1KgInsufficientVolume = scOutReturnSheet.getTieredAssessment0To1KgAssessedVolume() - scOutReturnSheet.getTieredAssessment0To1KgShipmentCount();
                if (tieredAssessment0To1KgInsufficientVolume > 0) {
                    scOutReturnSheet.setTieredAssessment0To1KgInsufficientVolume(tieredAssessment0To1KgInsufficientVolume);
                } else {
                    scOutReturnSheet.setTieredAssessment0To1KgInsufficientVolume(0);
                }
                //金额
                scOutReturnSheet.setTieredAssessment0To1KgAmount(scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard().multiply(BigDecimal.valueOf(tieredAssessment0To1KgInsufficientVolume)));

                //0-999散单考核
                Integer throwawayAssessment0To999KgInsufficientVolume = scOutReturnSheet.getThrowawayAssessment0To999KgAssessedVolume() - scOutReturnSheet.getThrowawayAssessment0To999KgShipmentCount();
                if (throwawayAssessment0To999KgInsufficientVolume > 0) {
                    scOutReturnSheet.setThrowawayAssessment0To999KgInsufficientVolume(throwawayAssessment0To999KgInsufficientVolume);
                } else {
                    scOutReturnSheet.setThrowawayAssessment0To999KgInsufficientVolume(0);
                }
                scOutReturnSheet.setThrowawayAssessment0To999KgAmount(scOutReturnSheet.getThrowawayAssessment0To999KgAssessmentStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getThrowawayAssessment0To999KgInsufficientVolume())));

                //0-999业务考核
                //不足业务量
                Integer businessAssessment0To999KgInsufficientVolume = scOutReturnSheet.getBusinessAssessment0To999KgAssessedVolume() - scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount();
                if (businessAssessment0To999KgInsufficientVolume > 0) {
                    scOutReturnSheet.setBusinessAssessment0To999KgInsufficientVolume(businessAssessment0To999KgInsufficientVolume);
                } else {
                    scOutReturnSheet.setBusinessAssessment0To999KgInsufficientVolume(0);
                }
                //金额
                scOutReturnSheet.setBusinessAssessment0To999KgAmount(scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getBusinessAssessment0To999KgInsufficientVolume())));

                BigDecimal totalRebateAmount = scOutReturnSheet.getZeroToHalfKgAmount().add(scOutReturnSheet.getHalfTo1KgAmount().add(scOutReturnSheet.getOneTo3KgAmount().add(scOutReturnSheet.getThreeToTenKgAmount().add(scOutReturnSheet.getTenTo399KgAmount().add(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount().add(scOutReturnSheet.getIncrementalRebate0To1KgAmount().add(scOutReturnSheet.getCumulativeRebate0To2KgAmount().add(scOutReturnSheet.getTieredAssessment0To1KgAmount().add(scOutReturnSheet.getThrowawayAssessment0To999KgAmount()).add(scOutReturnSheet.getBusinessAssessment0To999KgAmount())))))))));

                scOutReturnSheet.setTotalRebateAmount(totalRebateAmount);
                scOutReturnSheet.setSingleTicketRebate(totalRebateAmount.divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), mc));

                //一客一价返利
                //发件数
//    Integer oneToThreeKgRebateShipmentCountReceipt = scOutReturnSheetMapper.selectClientOneToThree(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
//    scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(oneToThreeKgRebateShipmentCountReceipt);
                // 日业务量

                scOutReturnSheet.setOneToThreeKgRebateDailyVolumeReceipt(oneToThreeKgRebateDailyVolumeReceipt);
                scOutReturnSheet.setOneToThreeKgRebateAssessedVolumeReceipt(scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() * dateDifference);
                // 考核业务量
                // 剔除票数
                // 返利业务量
                /*Integer oneToThreeKgRebateRebateVolumeReceipt = scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() - oneToThreeKgRebateDailyVolumeReceipt;
                if (oneToThreeKgRebateRebateVolumeReceipt > 0) {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(oneToThreeKgRebateRebateVolumeReceipt);
                } else {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                }
                //修改前
                */
                scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(oneToThreeKgRebateRebateVolumeReceipt);//修改后
                //返利一客一价金额
                scOutReturnSheet.setOneToThreeKgRebateAmountReceipt(oneToThreeKgRebateAmountReceipt);
                //返利标准
                scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(
                        scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt() != 0 ?
                                scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().divide(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt())) : BigDecimal.valueOf(0.00)
                );
                //0-0.5kg超基数返利
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyQualified(scOutReturnSheet.getZeroToHalfKgPolicyQualified());
                //基数
                //从承包区中汇总
                //查询客户的所有数据
                ScOutReturnSheetVo sheetVo = new ScOutReturnSheetVo();
                BeanUtils.copyProperties(vo, sheetVo);
                PageDate pageDates = vo.getPageDate();
                sheetVo.setNetworkLevel(1);
                pageDate.setPageNum(1);
                pageDate.setPageSize(100000);
                sheetVo.setPageDate(pageDates);
                List<ScOutReturnSheet> scOutReturnSheets1 = collectExport(sheetVo);
                int zeroToHalfKgExceedBasePolicyBase = 0;
                for (ScOutReturnSheet outReturnSheet : scOutReturnSheets1) {
                    zeroToHalfKgExceedBasePolicyBase += outReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
                }
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyBase(zeroToHalfKgExceedBasePolicyBase);
                //返利票数
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(
                        //Math.max(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() - scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase(), 0));  //修改前
                        Math.max(zeroToHalfKgExceedBasePolicyDifference, 0));
                //返利标准
                //0-0.5kg超基数返利-返利标准
                BigDecimal zeroToHalfKgExceedBasePolicyDifferenceBigDecimal = new BigDecimal(zeroToHalfKgExceedBasePolicyDifference);
                if (zeroToHalfKgExceedBasePolicyDifferenceBigDecimal.intValue() != 0) {
                    BigDecimal divide = zeroToHalfKgExceedBasePolicyRebate.divide(zeroToHalfKgExceedBasePolicyDifferenceBigDecimal, 2, RoundingMode.HALF_UP);
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(divide);
                } else {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(new BigDecimal(0));

                }
                //金额
                //修改前       //scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference())));
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(zeroToHalfKgExceedBasePolicyRebate); //修改后

                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyGrossProfit(scOutReturnSheet.getZeroToHalfKgAmount().subtract(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate()));
//    if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference().compareTo(0) != 0) {
//        scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(
//                scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate()
//                        .divide(BigDecimal.valueOf(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference()), mc)
//        );
//    } else {
//        // 如果分母为零，决定如何处理这种情况，这里示例为设置为0
//        scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(BigDecimal.ZERO);
//        // 可能还需要记录日志或抛出警告，告知分母为零的情况
//    }
                //0.5-1kg超基数返利
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(scOutReturnSheet.getHalfTo1KgPolicyQualified());
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(zeroToHalfKgExceedBasePolicyBase);
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(
                        //修改前//Math.max(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() - scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase(), 0)
                        halfTo1KgExceedBasePolicyDifference//修改后
                );

                //返利标准
                //金额
                //修改前//scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference())));
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(halfTo1KgExceedBasePolicyRebate);//修改后
                //修改前//scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebateStandard(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified()), mc));
                if (halfTo1KgExceedBasePolicyRebate.intValue() != 0) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebateStandard(halfTo1KgExceedBasePolicyRebate.divide(BigDecimal.valueOf(halfTo1KgExceedBasePolicyDifference), mc));
                } else {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebateStandard(new BigDecimal(0));
                }
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyGrossProfit(scOutReturnSheet.getHalfTo1KgAmount().subtract(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate()));

                //1-3kg分档返利
                //修改前//scOutReturnSheet.setOneTo3KgRebatePolicyRebate(scOutReturnSheetMapper.countAmount(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0));
                scOutReturnSheet.setOneTo3KgRebatePolicyRebate(oneTo3KgRebatePolicyRebate);
                //修改前//scOutReturnSheet.setOneTo3KgRebatePolicyRebateStandard(scOutReturnSheet.getOneTo3KgRebatePolicyRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getOneTo3KgRebatePolicyQualified()), mc));
                scOutReturnSheet.setOneTo3KgRebatePolicyRebateStandard(oneTo3KgRebatePolicyRebate.divide(BigDecimal.valueOf(scOutReturnSheet.getOneTo3KgRebatePolicyQualified()), mc));
                scOutReturnSheet.setOneTo3KgRebatePolicyGrossProfit(scOutReturnSheet.getOneTo3KgAmount().subtract(scOutReturnSheet.getOneTo3KgRebatePolicyRebate()));
                //3-999kg分档返利
                //修改前//scOutReturnSheet.setThreeTo999KgRebatePolicyRebate(scOutReturnSheetMapper.countAmount(vo.getStartTime(), vo.getEndTime(), 3.0, 999.0));
                scOutReturnSheet.setThreeTo999KgRebatePolicyRebate(threeTo999KgRebatePolicyRebate);//修改后
                int threeTo999 = scOutReturnSheet.getThreeToTenKgShipments() + scOutReturnSheet.getTenTo399KgShipments();
                scOutReturnSheet.setThreeTo999KgRebatePolicyQualified(threeTo999/* + scOutReturnSheet.getTenTo399KgShipments()*/);
                scOutReturnSheet.setThreeTo999KgRebatePolicyRebateStandard(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getThreeTo999KgRebatePolicyQualified()), mc));
                scOutReturnSheet.setThreeTo999KgRebatePolicyGrossProfit(scOutReturnSheet.getThreeToTenKgAmount().add(scOutReturnSheet.getTenTo399KgAmount()).subtract(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate()));
                //1-3kg叠加返利
                //修改前//scOutReturnSheet.setOneToThreeKgAdditiveRebate(scOutReturnSheetMapper.countAmount(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0));
                scOutReturnSheet.setOneToThreeKgAdditiveRebate(oneToThreeKgAdditiveRebate);//修改后
                scOutReturnSheet.setOneToThreeKgAdditiveRebateStandard(scOutReturnSheet.getOneToThreeKgAdditiveRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets()), mc));
                scOutReturnSheet.setOneToThreeKgAdditiveGrossProfit(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount().subtract(scOutReturnSheet.getOneToThreeKgAdditiveRebate()));
                scOutReturnSheet.setOneToThreeKgAdditiveRebateCompliantTickets(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard());
                //0-2kg叠加返利
                //修改前//scOutReturnSheet.setZeroToTwoKgAdditiveRebate(scOutReturnSheetMapper.countAmount(vo.getStartTime(), vo.getEndTime(), 0.0, 2.0));
                scOutReturnSheet.setZeroToTwoKgAdditiveRebate(zeroToTwoKgAdditiveRebate);
                scOutReturnSheet.setZeroToTwoKgAdditiveRebateStandard(scOutReturnSheet.getZeroToTwoKgAdditiveRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets()), mc));
                scOutReturnSheet.setZeroToTwoKgAdditiveGrossProfit(scOutReturnSheet.getCumulativeRebate0To2KgAmount().subtract(scOutReturnSheet.getZeroToTwoKgAdditiveRebate()));
                scOutReturnSheet.setZeroToTwoKgAdditiveRebateCompliantTickets(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets());

                //总部净返利合计
                BigDecimal headquartersNetRebateTotal = new BigDecimal(0.00);
                if (scOutReturnSheet.getTotalRebateAmount() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getTotalRebateAmount());
                }
                if (scOutReturnSheet.getExclusionAdjustment() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getExclusionAdjustment());
                }
                if (scOutReturnSheet.getOneToThreeKgRebateAmountReceipt() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt());
                }
                scOutReturnSheet.setHeadquartersNetRebateTotal(headquartersNetRebateTotal);

                scOutReturnSheet.setOneToThreeKgRebateDailyVolume(scOutReturnSheetMapper.countReturn1To3());
                scOutReturnSheet.setOneToThreeKgRebateAssessedVolume(scOutReturnSheet.getOneToThreeKgRebateDailyVolume() * dateDifference);
// 修改前//   scOutReturnSheet.setOneToThreeKgRebateRebateVolume(scOutReturnSheet.getOneToThreeKgRebateShipmentCount() - scOutReturnSheet.getOneToThreeKgRebateDailyVolume());
                //修改后
                scOutReturnSheet.setOneToThreeKgRebateRebateVolume(oneToThreeKgRebateRebateVolume);
                //修改前//scOutReturnSheet.setOneToThreeKgRebateRebate(scOutReturnSheetMapper.countAmount(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0));
                //修改后
                scOutReturnSheet.setOneToThreeKgRebateRebate(oneToThreeKgRebateRebate);
                scOutReturnSheet.setOneToThreeKgRebateGrossProfit(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().subtract(scOutReturnSheet.getOneToThreeKgRebateRebate()));
                scOutReturnSheet.setOneToThreeKgRebateRebateStandard(
                        scOutReturnSheet.getOneToThreeKgRebateRebateVolume() != 0 ?
                                scOutReturnSheet.getOneToThreeKgRebateRebate().divide(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolume()), mc)
                                : BigDecimal.valueOf(0));
                //支付承包区返利合计
                BigDecimal paymentContractAreaRebateTotal = new BigDecimal(0.00);
                if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate());
                }
                if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate());
                }
                if (scOutReturnSheet.getOneTo3KgRebatePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneTo3KgRebatePolicyRebate());
                }
                if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate());
                }
                if (scOutReturnSheet.getOneToThreeKgAdditiveRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgAdditiveRebate());
                }
                if (scOutReturnSheet.getZeroToTwoKgAdditiveRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToTwoKgAdditiveRebate());
                }
                if (scOutReturnSheet.getOneToThreeKgRebateRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateRebate());
                }
                scOutReturnSheet.setPaymentContractAreaRebateTotal(paymentContractAreaRebateTotal);
                //应付承包区金额-单票返利
                scOutReturnSheet.setSingleTicketRebateTotal(scOutReturnSheet.getPaymentContractAreaRebateTotal().divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), 3));
                //返利毛利
                scOutReturnSheet.setRebateGrossProfit(scOutReturnSheet.getHeadquartersNetRebateTotal().subtract(scOutReturnSheet.getPaymentContractAreaRebateTotal()));
            }
        }

        List<ScOutReturnSheet> scOutReturnSheets1 = null;
        if (vo.getNetworkLevel().equals(1) || vo.getNetworkLevel().equals(2)) {
            //剔除票数
            List<Map<String, Object>> zeroToHalfKgEliminateNumList = null;
            List<Map<String, Object>> halfTo1KgEliminateNumList = null;
            List<Map<String, Object>> oneTo3KgEliminateNumList = null;
            List<Map<String, Object>> threeToTenKgEliminateNumList = null;
            if (vo.getNetworkLevel().equals(2)) {
                zeroToHalfKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 0.0, 0.5);
                halfTo1KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 0.5, 1.0);
                oneTo3KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
                threeToTenKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 3.0, 10.0);
            } else {
                zeroToHalfKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMapByContractArea(vo.getStartTime(), vo.getEndTime(), 0.0, 0.5);
                halfTo1KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMapByContractArea(vo.getStartTime(), vo.getEndTime(), 0.5, 1.0);
                oneTo3KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMapByContractArea(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
                threeToTenKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMapByContractArea(vo.getStartTime(), vo.getEndTime(), 3.0, 10.0);
            }
            //0-0.5分档返利剔除票数
            Map<String, Integer> zeroToHalfKgEliminateNumMap = zeroToHalfKgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
            //0.5-1kg分档返利-剔除票数
            Map<String, Integer> halfTo1KgEliminateNumMap = halfTo1KgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
            //1-3kg分档返利-剔除票数
            Map<String, Integer> oneTo3KgEliminateNumMap = oneTo3KgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
            //3-10kg分档返利-剔除票数
            Map<String, Integer> threeToTenKgEliminateNumMap = threeToTenKgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));

            //承包区的数据为客户数据累加，以下map存储的是客户的数据的累加和
            //paymentContractAreaRebateTotal
            Map<String, BigDecimal> paymentContractAreaRebateTotalMap = new HashMap<>();
            //0-0.5kg超基数返利-基数
            Integer zeroToHalfKgExceedBasePolicyBase = 0;
            Integer halfTo1KgExceedBasePolicyBase = 0;
            //0-0.5kg超基数返利-返利票数
            Map<String, Integer> zeroToHalfKgExceedBasePolicyDifferenceMap = new HashMap<>();
            //0-0.5kg超基数返利-返利
            Map<String, BigDecimal> zeroToHalfKgExceedBasePolicyRebateMap = new HashMap<>();
            //0.5-1kg超基数返利-基数
            Map<String, Integer> halfTo1KgExceedBasePolicyBaseMap = new HashMap<>();
            //0.5-1kg超基数返利-差额
            Map<String, Integer> halfTo1KgExceedBasePolicyDifferenceMap = new HashMap<>();
            //0.5-1kg超基数返利-返利
            Map<String, BigDecimal> halfTo1KgExceedBasePolicyRebateMap = new HashMap<>();
            //0.5-1kg超基数返利-毛利
            Map<String, BigDecimal> halfTo1KgExceedBasePolicyGrossProfitMap = new HashMap<>();
            //1-3kg分档返利-符合政策票
            Map<String, Integer> oneTo3KgRebatePolicyQualifiedMap = new HashMap<>();
            //1-3kg分档返利-返利
            Map<String, BigDecimal> oneTo3KgRebatePolicyRebateMap = new HashMap<>();
            //1-3kg分档返利-毛利
            Map<String, BigDecimal> oneTo3KgRebatePolicyGrossProfitMap = new HashMap<>();
            if (vo.getNetworkLevel().equals(1)) {

                //查询客户的所有数据
                ScOutReturnSheetVo sheetVo = new ScOutReturnSheetVo();
                BeanUtils.copyProperties(vo, sheetVo);
                PageDate pageDate = vo.getPageDate();
//Integer pageNum = pageDate.getPageNum();
//Integer pageSize = pageDate.getPageSize();
                sheetVo.setNetworkLevel(2);
                pageDate.setPageNum(1);
                pageDate.setPageSize(100000);
                sheetVo.setPageDate(pageDate);
                List<ScOutReturnSheet> scOutReturnSheets = this.collectExport(sheetVo);
                scOutReturnSheets1 = scOutReturnSheets;

                //获取承包区字典
                List<ScOutBoundSendSheet> scOutBoundSendSheets = scOutBoundSendSheetMapper.selectAll();

                //承包区数据map初始化
                paymentContractAreaRebateTotalMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));
                halfTo1KgExceedBasePolicyBaseMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> 0));
                zeroToHalfKgExceedBasePolicyDifferenceMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> 0));
                zeroToHalfKgExceedBasePolicyRebateMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));
                halfTo1KgExceedBasePolicyDifferenceMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> 0));
                halfTo1KgExceedBasePolicyRebateMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));
                halfTo1KgExceedBasePolicyGrossProfitMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));
                oneTo3KgRebatePolicyQualifiedMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> 0));
                oneTo3KgRebatePolicyRebateMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));
                oneTo3KgRebatePolicyGrossProfitMap = scOutBoundSendSheets.stream().collect(Collectors.toMap(a -> a.getContractArea(), a -> BigDecimal.valueOf(0.00)));

                //将客户的数据累加的承包区对应字段的map中。
                //父客户不属于固定12个承包区的归属为辽宁盘锦公司
                for (ScOutReturnSheet scOutReturnSheet : scOutReturnSheets) {
                    String name = scOutReturnSheet.getName();
                    BigDecimal bigDecimal = paymentContractAreaRebateTotalMap.get(name);
                    if (bigDecimal == null || name.equals("辽宁盘锦公司")) {
                        name = "辽宁盘锦公司";
                        bigDecimal = paymentContractAreaRebateTotalMap.get(name);

                        if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase() == null) {
                            scOutReturnSheet.setZeroToHalfKgExceedBasePolicyBase(0);
                        }
                        zeroToHalfKgExceedBasePolicyBase = zeroToHalfKgExceedBasePolicyBase + scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
                        if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() == null) {
                            scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(0);
                        }
                        halfTo1KgExceedBasePolicyBase = halfTo1KgExceedBasePolicyBase + scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase();
                    }
                    if (scOutReturnSheet.getPaymentContractAreaRebateTotal() == null) {
                        scOutReturnSheet.setPaymentContractAreaRebateTotal(BigDecimal.valueOf(0.00));
                    }
                    paymentContractAreaRebateTotalMap.put(name, bigDecimal.add(scOutReturnSheet.getPaymentContractAreaRebateTotal()));

                    String sheetName = scOutReturnSheet.getName();
                    Integer zero = zeroToHalfKgExceedBasePolicyDifferenceMap.get(sheetName);
                    if (zero == null || sheetName.equals("辽宁盘锦公司")) {
                        sheetName = "辽宁盘锦公司";
                        zero = zeroToHalfKgExceedBasePolicyDifferenceMap.get(sheetName);
                    }
                    Integer zeroToHalfKgExceedBasePolicyDifference = scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference();
                    if (zeroToHalfKgExceedBasePolicyDifference == null) {
                        zeroToHalfKgExceedBasePolicyDifference = 0;
                        scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
                    }
                    zeroToHalfKgExceedBasePolicyDifferenceMap.put(sheetName, zero + scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference());

                    String halfName = scOutReturnSheet.getName();
                    Integer half = halfTo1KgExceedBasePolicyBaseMap.get(halfName);
                    if (half == null) {
                        halfName = "辽宁盘锦公司";
                        half = halfTo1KgExceedBasePolicyBaseMap.get(halfName);
                    }
                    if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() == null) {
                        scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(0);
                    }
                    halfTo1KgExceedBasePolicyBaseMap.put(halfName, half + scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase());

                    //当前承包区的名称
                    String zeroDiffName = scOutReturnSheet.getName();
                    //获取map中存储的值
                    BigDecimal zeroDiff = zeroToHalfKgExceedBasePolicyRebateMap.get(zeroDiffName);
                    //map中不包含这个名称，说明名称不属于12个承包区
                    if (zeroDiff == null) {
                        //不属于则归属于辽宁盘锦公司
                        zeroDiffName = "辽宁盘锦公司";
                        zeroDiff = zeroToHalfKgExceedBasePolicyRebateMap.get(zeroDiffName);
                    }
                    //将值添加到map中key对应的value中
                    zeroToHalfKgExceedBasePolicyRebateMap.put(zeroDiffName, zeroDiff.add(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate()));

                    String helf1Name = scOutReturnSheet.getName();
                    Integer helf1 = halfTo1KgExceedBasePolicyDifferenceMap.get(helf1Name);
                    if (helf1 == null) {
                        helf1Name = "辽宁盘锦公司";
                        helf1 = halfTo1KgExceedBasePolicyDifferenceMap.get(helf1Name);
                    }
                    halfTo1KgExceedBasePolicyDifferenceMap.put(helf1Name, helf1 + scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference());

                    String halfTo1KgExceedBasePolicyRebateMapName = scOutReturnSheet.getName();
                    BigDecimal halfTo1KgExceedBasePolicyRebateMapValue = halfTo1KgExceedBasePolicyRebateMap.get(halfTo1KgExceedBasePolicyRebateMapName);
                    if (halfTo1KgExceedBasePolicyRebateMapValue == null) {
                        halfTo1KgExceedBasePolicyRebateMapName = "辽宁盘锦公司";
                        halfTo1KgExceedBasePolicyRebateMapValue = halfTo1KgExceedBasePolicyRebateMap.get(helf1Name);
                    }
                    halfTo1KgExceedBasePolicyRebateMap.put(halfTo1KgExceedBasePolicyRebateMapName, halfTo1KgExceedBasePolicyRebateMapValue.add(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate()));


                    String halfTo1KgExceedBasePolicyGrossProfitMapName = scOutReturnSheet.getName();
                    BigDecimal halfTo1KgExceedBasePolicyGrossProfitMapValue = halfTo1KgExceedBasePolicyGrossProfitMap.get(halfTo1KgExceedBasePolicyGrossProfitMapName);
                    if (halfTo1KgExceedBasePolicyGrossProfitMapValue == null) {
                        halfTo1KgExceedBasePolicyGrossProfitMapName = "辽宁盘锦公司";
                        halfTo1KgExceedBasePolicyGrossProfitMapValue = halfTo1KgExceedBasePolicyGrossProfitMap.get(helf1Name);
                    }
                    halfTo1KgExceedBasePolicyGrossProfitMap.put(halfTo1KgExceedBasePolicyGrossProfitMapName, halfTo1KgExceedBasePolicyGrossProfitMapValue.add(scOutReturnSheet.getHalfTo1KgExceedBasePolicyGrossProfit()));


                    String oneTo3KgRebatePolicyQualifiedMapName = scOutReturnSheet.getName();
                    Integer oneTo3KgRebatePolicyQualifiedMapValue = oneTo3KgRebatePolicyQualifiedMap.get(oneTo3KgRebatePolicyQualifiedMapName);
                    if (oneTo3KgRebatePolicyQualifiedMapValue == null) {
                        oneTo3KgRebatePolicyQualifiedMapName = "辽宁盘锦公司";
                        oneTo3KgRebatePolicyQualifiedMapValue = oneTo3KgRebatePolicyQualifiedMap.get(oneTo3KgRebatePolicyQualifiedMapName);
                    }
                    oneTo3KgRebatePolicyQualifiedMap.put(oneTo3KgRebatePolicyQualifiedMapName, oneTo3KgRebatePolicyQualifiedMapValue + scOutReturnSheet.getOneTo3KgRebatePolicyQualified());


                    String oneTo3KgRebatePolicyRebateMapName = scOutReturnSheet.getName();
                    BigDecimal oneTo3KgRebatePolicyRebateMapValue = oneTo3KgRebatePolicyRebateMap.get(oneTo3KgRebatePolicyRebateMapName);
                    if (oneTo3KgRebatePolicyRebateMapValue == null) {
                        oneTo3KgRebatePolicyRebateMapName = "辽宁盘锦公司";
                        oneTo3KgRebatePolicyRebateMapValue = oneTo3KgRebatePolicyRebateMap.get(oneTo3KgRebatePolicyRebateMapName);
                    }
                    oneTo3KgRebatePolicyRebateMap.put(oneTo3KgRebatePolicyRebateMapName, oneTo3KgRebatePolicyRebateMapValue.add(scOutReturnSheet.getOneTo3KgRebatePolicyRebate()));


                    String oneTo3KgRebatePolicyGrossProfitMapName = scOutReturnSheet.getName();
                    BigDecimal oneTo3KgRebatePolicyGrossProfitMapValue = oneTo3KgRebatePolicyGrossProfitMap.get(oneTo3KgRebatePolicyGrossProfitMapName);
                    if (oneTo3KgRebatePolicyGrossProfitMapValue == null) {
                        oneTo3KgRebatePolicyGrossProfitMapName = "辽宁盘锦公司";
                        oneTo3KgRebatePolicyGrossProfitMapValue = oneTo3KgRebatePolicyGrossProfitMap.get(oneTo3KgRebatePolicyGrossProfitMapName);
                    }
                    oneTo3KgRebatePolicyGrossProfitMap.put(oneTo3KgRebatePolicyGrossProfitMapName, oneTo3KgRebatePolicyGrossProfitMapValue.add(scOutReturnSheet.getOneTo3KgRebatePolicyGrossProfit()));

                }

            }


            for (ScOutReturnSheet scOutReturnSheet : collect) {
//    scOutReturnSheet.setTieredAssessment0To1KgAssessedVolume(scOutReturnSheet.getTieredAssessment0To1KgDailyVolume()*dateDifference);
//    scOutReturnSheet.setBusinessAssessment0To999KgAssessedVolume(scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume()*dateDifference);

                //Integer zeroToHalfKgExceedBasePolicyBase = scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
//0-0.5kg分档返利-剔除票数
                Integer zeroToHalfKgEliminateNum = zeroToHalfKgEliminateNumMap.get(scOutReturnSheet.getName());
                if (zeroToHalfKgEliminateNum == null) {
                    zeroToHalfKgEliminateNum = 0;
                }
                scOutReturnSheet.setZeroToHalfKgEliminateNum(zeroToHalfKgEliminateNum);
//0-0.5kg分档返利-符合政策票数
                Integer zeroToHalfKgPolicyQualified = scOutReturnSheet.getZeroToHalfKgShipments() - zeroToHalfKgEliminateNum;
                scOutReturnSheet.setZeroToHalfKgPolicyQualified(zeroToHalfKgPolicyQualified);
//0-0.5kg分档返利-金额
                scOutReturnSheet.setZeroToHalfKgAmount(scOutReturnSheet.getZeroToHalfKgRebateStandard().multiply(BigDecimal.valueOf(zeroToHalfKgPolicyQualified)));

//0.5-1kg分档返利-剔除票数
                Integer halfTo1KgEliminateNum = halfTo1KgEliminateNumMap.get(scOutReturnSheet.getName());
                if (halfTo1KgEliminateNum == null) {
                    halfTo1KgEliminateNum = 0;
                }
                scOutReturnSheet.setHalfTo1KgEliminateNum(halfTo1KgEliminateNum);
//0.5-1kg分档返利-符合政策票数
                Integer halfTo1KgPolicyQualified = scOutReturnSheet.getHalfTo1KgShipments() - halfTo1KgEliminateNum;
                scOutReturnSheet.setHalfTo1KgPolicyQualified(halfTo1KgPolicyQualified);
//0.5-1kg分档返利-金额
                scOutReturnSheet.setHalfTo1KgAmount(scOutReturnSheet.getHalfTo1KgRebateStandard().multiply(BigDecimal.valueOf(halfTo1KgPolicyQualified)));

//1-3kg分档返利-剔除票数
                Integer oneTo3KgEliminateNum = oneTo3KgEliminateNumMap.get(scOutReturnSheet.getName());
                if (oneTo3KgEliminateNum == null) {
                    oneTo3KgEliminateNum = 0;
                }
                scOutReturnSheet.setOneTo3KgEliminateNum(oneTo3KgEliminateNum);
//1-3kg分档返利-符合政策票数
                Integer oneTo3KgPolicyQualified = scOutReturnSheet.getOneTo3KgShipments() - oneTo3KgEliminateNum;
                scOutReturnSheet.setOneTo3KgPolicyQualified(oneTo3KgPolicyQualified);
//1-3kg分档返利-金额
                scOutReturnSheet.setOneTo3KgAmount(scOutReturnSheet.getOneTo3KgRebateStandard().multiply(BigDecimal.valueOf(oneTo3KgPolicyQualified)));

//3-10kg分档返利-剔除票数
                Integer threeToTenKgEliminateNum = threeToTenKgEliminateNumMap.get(scOutReturnSheet.getName());
                if (threeToTenKgEliminateNum == null) {
                    threeToTenKgEliminateNum = 0;
                }
                scOutReturnSheet.setThreeToTenKgEliminateNum(threeToTenKgEliminateNum);
//3-10kg分档返利-符合政策票数
                Integer threeToTenKgPolicyQualified = scOutReturnSheet.getThreeToTenKgShipments() - threeToTenKgEliminateNum;
                scOutReturnSheet.setThreeToTenKgPolicyQualified(threeToTenKgPolicyQualified);
//3-10kg分档返利-金额
                scOutReturnSheet.setThreeToTenKgAmount(scOutReturnSheet.getThreeToTenKgRebateStandard().multiply(BigDecimal.valueOf(threeToTenKgPolicyQualified)));

//           叠加返利1-3kg-剔除票数
//    Integer xoverlayPolicyOneTo3KgPolicyQualified = scOutReturnSheetMapper.deleteTicket(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0, scOutReturnSheet.getName());
//    scOutReturnSheet.setXoverlayPolicyOneTo3KgPolicyQualified(xoverlayPolicyOneTo3KgPolicyQualified);
//
////叠加返利1-3kg-符合政策票数
//    if (vo.getStartTime() != null && vo.getEndTime() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() != null && xoverlayPolicyOneTo3KgPolicyQualified != null) {
//        int xoverlayPolicyOneTo3KgRebateStandard = scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments()
//                - scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
//                - xoverlayPolicyOneTo3KgPolicyQualified;
//
//// 如果结果小于0，设置为0
//        scOutReturnSheet.setXoverlayPolicyOneTo3KgRebateStandard(Math.max(xoverlayPolicyOneTo3KgRebateStandard, 0));

//    }

//叠加返利1-3kg-金额
//    if (scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard() != null) {
//        scOutReturnSheet.setXoverlayPolicyOneTo3KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().multiply(BigDecimal.valueOf(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard())));
//    }


//增量返利0-1kg-剔除票数
//    Integer incrementalRebate0To1KgExcludeTickets = scOutReturnSheetMapper.deleteTicket(vo.getStartTime(), vo.getEndTime(), 0.0, 1.0, scOutReturnSheet.getName());
//    scOutReturnSheet.setIncrementalRebate0To1KgExcludeTickets(incrementalRebate0To1KgExcludeTickets);
////增量返利0-1kg-符合政策票数
//    if (vo.getStartTime() != null && vo.getEndTime() != null) {
//        int incrementalRebate0To1KgPolicyCompliantTickets = scOutReturnSheet.getIncrementalRebate0To1KgShipmentCount()
//                - scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
//                - incrementalRebate0To1KgExcludeTickets;
//
//        // 如果结果小于0，设置为0
//        scOutReturnSheet.setIncrementalRebate0To1KgPolicyCompliantTickets(Math.max(incrementalRebate0To1KgPolicyCompliantTickets, 0));
//    }
//    //叠加返利1-3kg-金额
//    if (scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets() != null && scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage() != null) {
//        scOutReturnSheet.setIncrementalRebate0To1KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().multiply(BigDecimal.valueOf(scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets())));
//    }

                //0-2kg叠加返利-剔除票数
//    Integer cumulativeRebate0To2KgExcludeTickets = scOutReturnSheetMapper.deleteTicket(vo.getStartTime(), vo.getEndTime(), 0.0, 2.0, scOutReturnSheet.getName());
//    scOutReturnSheet.setCumulativeRebate0To2KgExcludeTickets(cumulativeRebate0To2KgExcludeTickets);
//
////0-2kg叠加返利-符合政策票数
//    if (vo.getStartTime() != null && vo.getEndTime() != null) {
//        int cumulativeRebate0To2KgPolicyCompliantTickets = scOutReturnSheet.getCumulativeRebate0To2KgShipmentCount()
//                - scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
//                - cumulativeRebate0To2KgExcludeTickets;
//        scOutReturnSheet.setCumulativeRebate0To2KgPolicyCompliantTickets(Math.max(cumulativeRebate0To2KgPolicyCompliantTickets, 0));
//    }
//    //0-2kg叠加返利-金额
//    scOutReturnSheet.setCumulativeRebate0To2KgAmount(scOutReturnSheet.getCumulativeRebate0To2KgRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets())));

//    // 0-1阶梯考核
//    //考核业务量
//    Integer tieredAssessment0To1KgInsufficientVolume = scOutReturnSheet.getTieredAssessment0To1KgDailyVolume() - scOutReturnSheet.getTieredAssessment0To1KgShipmentCount();
//    if (tieredAssessment0To1KgInsufficientVolume > 0) {
//        scOutReturnSheet.setTieredAssessment0To1KgInsufficientVolume(tieredAssessment0To1KgInsufficientVolume);
//    } else {
//        scOutReturnSheet.setTieredAssessment0To1KgInsufficientVolume(0);
//    }
//    //金额
//    scOutReturnSheet.setTieredAssessment0To1KgAmount(scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard().multiply(BigDecimal.valueOf(tieredAssessment0To1KgInsufficientVolume)));
//
//    //0-999业务考核
//    //不足业务量
//    Integer businessAssessment0To999KgInsufficientVolume = scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume() - scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount();
//    if (businessAssessment0To999KgInsufficientVolume > 0) {
//        scOutReturnSheet.setBusinessAssessment0To999KgInsufficientVolume(businessAssessment0To999KgInsufficientVolume);
//    } else {
//        scOutReturnSheet.setBusinessAssessment0To999KgInsufficientVolume(0);
//    }
                //金额
//    scOutReturnSheet.setBusinessAssessment0To999KgAmount(scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard().multiply(BigDecimal.valueOf(businessAssessment0To999KgInsufficientVolume)));

                BigDecimal totalRebateAmount = Optional.ofNullable(scOutReturnSheet.getZeroToHalfKgAmount())
                        .orElse(BigDecimal.ZERO)
                        .add(Optional.ofNullable(scOutReturnSheet.getHalfTo1KgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getOneTo3KgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getThreeToTenKgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getTenTo399KgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getIncrementalRebate0To1KgAmount())
                                .orElse(BigDecimal.ZERO))
                        .add(Optional.ofNullable(scOutReturnSheet.getCumulativeRebate0To2KgAmount())
                                .orElse(BigDecimal.ZERO));
                scOutReturnSheet.setTotalRebateAmount(totalRebateAmount);
                scOutReturnSheet.setTotalRebateAmount(totalRebateAmount);
                scOutReturnSheet.setSingleTicketRebate(totalRebateAmount.divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), mc));

                //一客一价返利
                //发件数
//    Integer oneToThreeKgRebateShipmentCountReceipt = scOutReturnSheetMapper.selectClientOneToThree(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
//    scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(oneToThreeKgRebateShipmentCountReceipt);
                // 日业务量
//    Integer oneToThreeKgRebateDailyVolumeReceipt = scOutReturnSheetMapper.selectClientOneToThreeDaily();
//    scOutReturnSheet.setOneToThreeKgRebateDailyVolumeReceipt(oneToThreeKgRebateDailyVolumeReceipt);
                // 考核业务量
                // 剔除票数
                // 返利业务量
                if (scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == null || scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == 0) {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                } else {
                    Integer oneToThreeKgRebateRebateVolumeReceipt = scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() - scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt();
                    if (oneToThreeKgRebateRebateVolumeReceipt > 0) {
                        scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
                    } else {
                        scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                    }
                }
                //金额
                scOutReturnSheet.setOneToThreeKgRebateAmountReceipt(scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt())));

                //0-0.5kg超基数返利
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyQualified(scOutReturnSheet.getZeroToHalfKgPolicyQualified());
                //基数
                if (scOutReturnSheet.getName().equals("辽宁盘锦公司")) {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyBase(0);
                }
                if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() == 0) {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
                }

                Integer zeroToHalfKgExceedBasePolicyDifference = scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() - scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
                if (zeroToHalfKgExceedBasePolicyDifference > 0) {
                    //scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(zeroToHalfKgExceedBasePolicyDifference);//修改前
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());//修改后
                } else {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
                }
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(zeroToHalfKgExceedBasePolicyDifferenceMap.get(scOutReturnSheet.getName()));
                }

                if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard() == null
                        || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().compareTo(BigDecimal.ZERO) == 0
                        || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() == null
                        || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() == 0) {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(BigDecimal.valueOf(0));
                } else {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference())));
                }
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(zeroToHalfKgExceedBasePolicyRebateMap.get(scOutReturnSheet.getName()));
                }
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyGrossProfit(scOutReturnSheet.getZeroToHalfKgAmount().subtract(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate()));

//    0.5-1kg超基数返利
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(scOutReturnSheet.getHalfTo1KgPolicyQualified());

                ScOutReturnSheetClient scOutReturnSheetClient = scOutReturnSheetClientMapper.selectBigClientByName(scOutReturnSheet.getName());
                if (scOutReturnSheetClient != null) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(scOutReturnSheetClient.getZeroPointFiveToOneSuperNum());
                }else{
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(0);
                }

                if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() == null) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(0);
                }
                if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() == null) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(0);
                }
//    返利票数
                if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() == 0) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(0);
                }
                Integer halfTo1KgExceedBasePolicyDifference = scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() - scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase();
                if (halfTo1KgExceedBasePolicyDifference > 0) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified());
                } else {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(0);
                }
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(halfTo1KgExceedBasePolicyDifferenceMap.get(scOutReturnSheet.getName()));
                }
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference())));
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(halfTo1KgExceedBasePolicyRebateMap.get(scOutReturnSheet.getName()));
                }
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyGrossProfit(scOutReturnSheet.getHalfTo1KgAmount().subtract(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate()));
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setHalfTo1KgExceedBasePolicyGrossProfit(halfTo1KgExceedBasePolicyGrossProfitMap.get(scOutReturnSheet.getName()));
                }
                //1-3分档返利
                scOutReturnSheet.setOneTo3KgRebatePolicyQualified(scOutReturnSheet.getOneTo3KgPolicyQualified());
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setOneTo3KgRebatePolicyQualified(oneTo3KgRebatePolicyQualifiedMap.get(scOutReturnSheet.getName()));
                }
                scOutReturnSheet.setOneTo3KgRebatePolicyRebate(scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneTo3KgRebatePolicyQualified())));
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setOneTo3KgRebatePolicyRebate(oneTo3KgRebatePolicyRebateMap.get(scOutReturnSheet.getName()));
                }
                //1-3kg分档返利-毛利
                scOutReturnSheet.setOneTo3KgRebatePolicyGrossProfit(scOutReturnSheet.getOneTo3KgAmount().subtract(scOutReturnSheet.getOneTo3KgRebatePolicyRebate()));
                if (vo.getNetworkLevel() == 1) {
                    scOutReturnSheet.setOneTo3KgRebatePolicyGrossProfit(oneTo3KgRebatePolicyGrossProfitMap.get(scOutReturnSheet.getName()));
                }
                //3-999分档返利
                scOutReturnSheet.setThreeTo999KgRebatePolicyRebate(scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getThreeTo999KgRebatePolicyQualified())));
//3-999kg分档返利-毛利
                scOutReturnSheet.setThreeTo999KgRebatePolicyGrossProfit(scOutReturnSheet.getThreeToTenKgAmount().subtract(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate()));
                //1-3叠加返利
                scOutReturnSheet.setOneToThreeKgAdditiveRebate(scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets())));
                BigDecimal xoverlayPolicyOneTo3KgAmount = scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount();
                BigDecimal oneToThreeKgAdditiveRebate = scOutReturnSheet.getOneToThreeKgAdditiveRebate();
                if (xoverlayPolicyOneTo3KgAmount != null && oneToThreeKgAdditiveRebate != null) {
                    scOutReturnSheet.setOneToThreeKgAdditiveGrossProfit(xoverlayPolicyOneTo3KgAmount.subtract(oneToThreeKgAdditiveRebate));
                }

                if (scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit() == null) {
                    scOutReturnSheet.setOneToThreeKgAdditiveGrossProfit(new BigDecimal(0.00));
                }

                //0-2叠加返利
                scOutReturnSheet.setZeroToTwoKgAdditiveRebate(scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets())));
                BigDecimal cumulativeRebate0To2KgAmount = scOutReturnSheet.getCumulativeRebate0To2KgAmount();
                BigDecimal zeroToTwoKgAdditiveRebate = scOutReturnSheet.getZeroToTwoKgAdditiveRebate();
                if (cumulativeRebate0To2KgAmount != null && zeroToTwoKgAdditiveRebate != null) {
                    scOutReturnSheet.setZeroToTwoKgAdditiveGrossProfit(cumulativeRebate0To2KgAmount.subtract(zeroToTwoKgAdditiveRebate));
                }

                //1-3kg一客一价返利
                Integer oneToThreeKgRebateRebateVolume = scOutReturnSheet.getOneToThreeKgRebateShipmentCount() - scOutReturnSheet.getOneToThreeKgRebateDailyVolume();
                if (oneToThreeKgRebateRebateVolume > 0 && scOutReturnSheet.getOneToThreeKgRebateDailyVolume() != 0) {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolume(scOutReturnSheet.getOneToThreeKgRebateShipmentCount());
                } else {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolume(0);
                }
                scOutReturnSheet.setOneToThreeKgRebateRebate(scOutReturnSheet.getOneToThreeKgRebateRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolume())));
                scOutReturnSheet.setOneToThreeKgRebateGrossProfit(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().subtract(scOutReturnSheet.getOneToThreeKgRebateRebate()));

                //总部净返利合计
                BigDecimal headquartersNetRebateTotal = new BigDecimal(0.00);
                if (scOutReturnSheet.getTotalRebateAmount() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getTotalRebateAmount());
                }
                if (scOutReturnSheet.getExclusionAdjustment() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getExclusionAdjustment());
                }
                if (scOutReturnSheet.getOneToThreeKgRebateAmountReceipt() != null) {
                    headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt());
                }
                scOutReturnSheet.setHeadquartersNetRebateTotal(headquartersNetRebateTotal);

                //支付承包区返利合计
                BigDecimal paymentContractAreaRebateTotal = new BigDecimal(0.00);
                if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate());
                }
                if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate());
                }
                if (scOutReturnSheet.getOneTo3KgRebatePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneTo3KgRebatePolicyRebate());
                }
                if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate());
                }
                if (scOutReturnSheet.getOneToThreeKgAdditiveRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgAdditiveRebate());
                }
                if (scOutReturnSheet.getZeroToTwoKgAdditiveRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToTwoKgAdditiveRebate());
                }
                if (scOutReturnSheet.getOneToThreeKgRebateRebate() != null) {
                    paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateRebate());
                }
                scOutReturnSheet.setPaymentContractAreaRebateTotal(paymentContractAreaRebateTotal);
                if (vo.getNetworkLevel() == 1) {
                    System.out.println("承包区:" + scOutReturnSheet.getName() + " == 返利票数: " + paymentContractAreaRebateTotalMap.get(scOutReturnSheet.getName()));
                    scOutReturnSheet.setPaymentContractAreaRebateTotal(paymentContractAreaRebateTotalMap.get(scOutReturnSheet.getName()));
                }
                //应付承包区金额-单票返利
                scOutReturnSheet.setSingleTicketRebateTotal(scOutReturnSheet.getPaymentContractAreaRebateTotal().divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), 3));
                //返利毛利
                scOutReturnSheet.setRebateGrossProfit(scOutReturnSheet.getHeadquartersNetRebateTotal().subtract(scOutReturnSheet.getPaymentContractAreaRebateTotal()));


                int threeTo999 = scOutReturnSheet.getThreeToTenKgShipments() + scOutReturnSheet.getTenTo399KgShipments();
                scOutReturnSheet.setThreeTo999KgRebatePolicyQualified(threeTo999);
                /*scOutReturnSheet.setThreeTo999KgRebatePolicyQualified(scOutReturnSheet.getThreeToTenKgPolicyQualified() + scOutReturnSheet.getTenTo399KgShipments());*/
                scOutReturnSheet.setOneToThreeKgAdditiveRebateCompliantTickets(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard());
                scOutReturnSheet.setZeroToTwoKgAdditiveRebateCompliantTickets(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets());
            }
        }
        if (vo.getNetworkLevel().equals(1)) {
            Integer oneToThreeKgRebateDailyVolumeReceipt = scOutReturnSheetMapper.selectClientOneToThreeDaily();

            List<ScOutReturnSheet> scOutReturnSheets = scOutReturnSheets1;


            for (ScOutReturnSheet scOutReturnSheet : collect) {
                if (scOutReturnSheet.getName().equals("辽宁盘锦公司")) {
                    //应收总部金额-1-3kg一客一价返利-发件数
                    Integer oneToThreeKgRebateShipmentCountReceipt = 0;
                    //应收总部金额-1-3kg一客一价返利-返利业务量
                    Integer oneToThreeKgRebateRebateVolumeReceipt = 0;
                    //"应付承包区金额-1-3kg一客一价返利-发件数")
                    Integer oneToThreeKgRebateShipmentCount = 0;
                    //"应付承包区金额-1-3kg一客一价返利-返利业务量")
                    Integer oneToThreeKgRebateRebateVolume = 0;

                    //"应收总部金额-1-3kg一客一价返利-一客一价金额")
                    BigDecimal oneToThreeKgRebateAmountReceipt = new BigDecimal(0.00);
                    //"应付承包区金额-1-3kg一客一价返利-返利")
                    BigDecimal oneToThreeKgRebateRebate = new BigDecimal(0.00);

                    //"应付承包区金额-1-3kg一客一价返利-返利标准")
                    BigDecimal oneToThreeKgRebateRebateStandardReceipt = new BigDecimal(0.00);
                    int count = 0;
                    //后加  //在这里计算合计中需要用到的明细总金额
                    for (ScOutReturnSheet outReturnSheet : scOutReturnSheets) {
                        if (outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() != 0) {
                            oneToThreeKgRebateShipmentCountReceipt += outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt();
                            oneToThreeKgRebateShipmentCount += outReturnSheet.getOneToThreeKgRebateShipmentCount();
                            if (outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() > outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt()) {
                                oneToThreeKgRebateRebateVolumeReceipt += outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt();
                            }
                            if (outReturnSheet.getOneToThreeKgRebateShipmentCount() - outReturnSheet.getOneToThreeKgRebateDailyVolume() > 0) {
                                oneToThreeKgRebateRebateVolume += outReturnSheet.getOneToThreeKgRebateShipmentCount();
                            }


                            if (outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == 0) {
                                outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                            } else {
                                if (outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() - outReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() > 0) {
                                    outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(outReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
                                } else {
                                    outReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                                }
                            }

                            BigDecimal multiply = outReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().multiply(BigDecimal.valueOf(outReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt()));
                            oneToThreeKgRebateAmountReceipt = oneToThreeKgRebateAmountReceipt.add(multiply);
                            oneToThreeKgRebateRebate = oneToThreeKgRebateRebate.add(outReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().multiply(BigDecimal.valueOf(outReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt())));
                            oneToThreeKgRebateRebateStandardReceipt = oneToThreeKgRebateRebateStandardReceipt.add(outReturnSheet.getOneToThreeKgRebateRebateStandardReceipt());
                            count++;
                        }
                    }

                    //应收总部金额-1-3kg一客一价返利-发件数
                    scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(oneToThreeKgRebateShipmentCountReceipt);
                    scOutReturnSheet.setOneToThreeKgRebateShipmentCount(oneToThreeKgRebateShipmentCount);

                    //一客一价返利
                    //发件数

                    // 日业务量

                    scOutReturnSheet.setOneToThreeKgRebateDailyVolumeReceipt(oneToThreeKgRebateDailyVolumeReceipt);
                    scOutReturnSheet.setOneToThreeKgRebateAssessedVolumeReceipt(scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() * dateDifference);
                    // 考核业务量
                    // 剔除票数
                    // 返利业务量

                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(oneToThreeKgRebateRebateVolumeReceipt);//修改后
                    //返利一客一价金额
                    scOutReturnSheet.setOneToThreeKgRebateAmountReceipt(oneToThreeKgRebateAmountReceipt);
                    //返利标准
                    /*scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(
                            scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt() != 0 ?
                                    scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().divide(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt())) : BigDecimal.valueOf(0.00)
                    );*/
                    scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(oneToThreeKgRebateRebateStandardReceipt.divide(BigDecimal.valueOf(count)));
                } else {
                    scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(0);
                    scOutReturnSheet.setOneToThreeKgRebateDailyVolumeReceipt(0);
                    scOutReturnSheet.setOneToThreeKgRebateAssessedVolumeReceipt(0);
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                    scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(BigDecimal.valueOf(0));
                    scOutReturnSheet.setOneToThreeKgRebateAmountReceipt(BigDecimal.valueOf(0));
                }
            }

        }
        return collect;
    }


    public List<ScOutReturnSheet> collectChildExport(ScOutReturnSheetVo vo) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        int dateDifference = 1;
        try {
            Date d1 = sdf.parse(vo.getStartTime());
            Date d2 = sdf.parse(vo.getEndTime());

            // 获取日历实例
            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(d1);
            cal2.setTime(d2);

            // 计算日期差
            long diffInMillis = Math.abs(cal2.getTimeInMillis() - cal1.getTimeInMillis());
            long diffInDays = diffInMillis / (24 * 60 * 60 * 1000);
            dateDifference = (int) (dateDifference + diffInDays);
            System.out.println("日期差为： " + diffInDays + " 天");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        PageHelper.startPage(vo.getPageDate());
        List<ScOutReturnSheet> collect = scOutReturnSheetMapper.collectChildClient(vo);

        List<ScOutReturnSheet> scOutReturnSheets1 = null;
        List<Map<String, Object>> zeroToHalfKgEliminateNumList = null;
        List<Map<String, Object>> halfTo1KgEliminateNumList = null;
        List<Map<String, Object>> oneTo3KgEliminateNumList = null;
        List<Map<String, Object>> threeToTenKgEliminateNumList = null;

        zeroToHalfKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 0.0, 0.5);
        halfTo1KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 0.5, 1.0);
        oneTo3KgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
        threeToTenKgEliminateNumList = scOutReturnSheetMapper.deleteTicketMap(vo.getStartTime(), vo.getEndTime(), 3.0, 10.0);

        //0-0.5分档返利剔除票数
        Map<String, Integer> zeroToHalfKgEliminateNumMap = zeroToHalfKgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
        //0.5-1kg分档返利-剔除票数
        Map<String, Integer> halfTo1KgEliminateNumMap = halfTo1KgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
        //1-3kg分档返利-剔除票数
        Map<String, Integer> oneTo3KgEliminateNumMap = oneTo3KgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));
        //3-10kg分档返利-剔除票数
        Map<String, Integer> threeToTenKgEliminateNumMap = threeToTenKgEliminateNumList.stream().collect(Collectors.toMap(a -> String.valueOf(a.get("name")), a -> Integer.valueOf(String.valueOf(a.get("value")))));

        //承包区的数据为客户数据累加，以下map存储的是客户的数据的累加和
        //paymentContractAreaRebateTotal
        Map<String, BigDecimal> paymentContractAreaRebateTotalMap = new HashMap<>();
        //0-0.5kg超基数返利-基数
        Integer zeroToHalfKgExceedBasePolicyBase = 0;
        //0-0.5kg超基数返利-返利票数
        Map<String, Integer> zeroToHalfKgExceedBasePolicyDifferenceMap = new HashMap<>();
        //0-0.5kg超基数返利-返利
        Map<String, BigDecimal> zeroToHalfKgExceedBasePolicyRebateMap = new HashMap<>();
        //0.5-1kg超基数返利-基数
        Map<String, Integer> halfTo1KgExceedBasePolicyBaseMap = new HashMap<>();
        //0.5-1kg超基数返利-差额
        Map<String, Integer> halfTo1KgExceedBasePolicyDifferenceMap = new HashMap<>();
        //0.5-1kg超基数返利-返利
        Map<String, BigDecimal> halfTo1KgExceedBasePolicyRebateMap = new HashMap<>();
        //0.5-1kg超基数返利-毛利
        Map<String, BigDecimal> halfTo1KgExceedBasePolicyGrossProfitMap = new HashMap<>();
        //1-3kg分档返利-符合政策票
        Map<String, Integer> oneTo3KgRebatePolicyQualifiedMap = new HashMap<>();
        //1-3kg分档返利-返利
        Map<String, BigDecimal> oneTo3KgRebatePolicyRebateMap = new HashMap<>();
        //1-3kg分档返利-毛利
        Map<String, BigDecimal> oneTo3KgRebatePolicyGrossProfitMap = new HashMap<>();

        for (ScOutReturnSheet scOutReturnSheet : collect) {
            HqClientRelation hqClientRelation = hqClientRelationMapper.selectClientByName(scOutReturnSheet.getName());
            if (hqClientRelation != null) {
                if (hqClientRelation.getLevel().equals("子客户")) {
                    ScOutReturnSheetClient scOutReturnSheetClient = selectClientSet(hqClientRelation.getId());
                    if (scOutReturnSheetClient.getOneToThreeOverlayStandardPay() != null) {
                        scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(
                                scOutReturnSheetClient.getOneToThreeOverlayStandardPay() != null ?
                                        scOutReturnSheetClient.getOneToThreeOverlayStandardPay() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(
                                scOutReturnSheetClient.getZeroToZeroPointFiveSuperStandard() != null ?
                                        scOutReturnSheetClient.getZeroToZeroPointFiveSuperStandard() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setZeroToHalfKgEliminateNum(scOutReturnSheetClient.getZeroToZeroPointFiveSuperNum());

                        scOutReturnSheet.setHalfTo1KgEliminateNum(scOutReturnSheetClient.getZeroPointFiveToOneSuperNum());

                        scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebateStandard(
                                scOutReturnSheetClient.getZeroPointFiveToOneSuperStandard() != null ?
                                        scOutReturnSheetClient.getZeroPointFiveToOneSuperStandard() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setOneTo3KgRebatePolicyRebateStandard(
                                scOutReturnSheetClient.getOneToThreeSplitStandard() != null ?
                                        scOutReturnSheetClient.getOneToThreeSplitStandard() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setThreeTo999KgRebatePolicyRebateStandard(
                                scOutReturnSheetClient.getMoreThanThreeSplitStandard() != null ?
                                        scOutReturnSheetClient.getMoreThanThreeSplitStandard() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setOneToThreeKgAdditiveRebateStandard(
                                scOutReturnSheetClient.getOneToThreeOverlayStandardPay() != null ?
                                        scOutReturnSheetClient.getOneToThreeOverlayStandardPay() : BigDecimal.ZERO
                        );
                        scOutReturnSheet.setZeroToTwoKgAdditiveRebateStandard(
                                scOutReturnSheetClient.getZeroToTwoOverlayStandardPay() != null ?
                                        scOutReturnSheetClient.getZeroToTwoOverlayStandardPay() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setOneToThreeKgRebateDailyVolume(scOutReturnSheetClient.getOneClientOnePriceNumPay());

                        scOutReturnSheet.setOneToThreeKgRebateRebateStandard(new BigDecimal(scOutReturnSheetClient.getOneClientOnePriceNumPay()));

                        scOutReturnSheet.setOneToThreeKgRebateRebateStandard(
                                scOutReturnSheetClient.getOneClientOnePriceStandardPay() != null ?
                                        scOutReturnSheetClient.getOneClientOnePriceStandardPay() : BigDecimal.ZERO
                        );

                    } else {
                        ScOutReturnSheetClient client = selectClientSet(hqClientRelation.getParentId());
                        scOutReturnSheet.setOneToThreeKgRebateRebateStandardReceipt(
                                client.getOneToThreeOverlayStandardPay() != null ? client.getOneToThreeOverlayStandardPay() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebateStandard(
                                client.getZeroToZeroPointFiveSuperStandard() != null ? client.getZeroToZeroPointFiveSuperStandard() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setZeroToHalfKgEliminateNum(client.getZeroToZeroPointFiveSuperNum());

                        scOutReturnSheet.setHalfTo1KgEliminateNum(client.getZeroPointFiveToOneSuperNum());

                        scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebateStandard(
                                client.getZeroPointFiveToOneSuperStandard() != null ? client.getZeroPointFiveToOneSuperStandard() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setOneTo3KgRebatePolicyRebateStandard(
                                client.getOneToThreeSplitStandard() != null ? client.getOneToThreeSplitStandard() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setThreeTo999KgRebatePolicyRebateStandard(
                                client.getMoreThanThreeSplitStandard() != null ? client.getMoreThanThreeSplitStandard() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setOneToThreeKgAdditiveRebateStandard(
                                client.getOneToThreeOverlayStandardPay() != null ? client.getOneToThreeOverlayStandardPay() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setZeroToTwoKgAdditiveRebateStandard(
                                client.getZeroToTwoOverlayStandardPay() != null ? client.getZeroToTwoOverlayStandardPay() : BigDecimal.ZERO
                        );

                        scOutReturnSheet.setOneToThreeKgRebateDailyVolume(client.getOneClientOnePriceNumPay());

                        scOutReturnSheet.setOneToThreeKgRebateRebateStandard(new BigDecimal(client.getOneClientOnePriceNumPay()));

                        scOutReturnSheet.setOneToThreeKgRebateRebateStandard(
                                client.getOneClientOnePriceStandardPay() != null ? client.getOneClientOnePriceStandardPay() : BigDecimal.ZERO
                        );

                    }
                }
            }

//    scOutReturnSheet.setTieredAssessment0To1KgAssessedVolume(scOutReturnSheet.getTieredAssessment0To1KgDailyVolume()*dateDifference);
//    scOutReturnSheet.setBusinessAssessment0To999KgAssessedVolume(scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume()*dateDifference);

            //Integer zeroToHalfKgExceedBasePolicyBase = scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
//0-0.5kg分档返利-剔除票数
            Integer zeroToHalfKgEliminateNum = zeroToHalfKgEliminateNumMap.get(scOutReturnSheet.getName());
            if (zeroToHalfKgEliminateNum == null) {
                zeroToHalfKgEliminateNum = 0;
            }
            scOutReturnSheet.setZeroToHalfKgEliminateNum(zeroToHalfKgEliminateNum);
//0-0.5kg分档返利-符合政策票数
            Integer zeroToHalfKgPolicyQualified = scOutReturnSheet.getZeroToHalfKgShipments() - zeroToHalfKgEliminateNum;
            scOutReturnSheet.setZeroToHalfKgPolicyQualified(zeroToHalfKgPolicyQualified);
//0-0.5kg分档返利-金额
            scOutReturnSheet.setZeroToHalfKgAmount(scOutReturnSheet.getZeroToHalfKgRebateStandard().multiply(BigDecimal.valueOf(zeroToHalfKgPolicyQualified)));

//0.5-1kg分档返利-剔除票数
            Integer halfTo1KgEliminateNum = halfTo1KgEliminateNumMap.get(scOutReturnSheet.getName());
            if (halfTo1KgEliminateNum == null) {
                halfTo1KgEliminateNum = 0;
            }
            scOutReturnSheet.setHalfTo1KgEliminateNum(halfTo1KgEliminateNum);
//0.5-1kg分档返利-符合政策票数
            Integer halfTo1KgPolicyQualified = scOutReturnSheet.getHalfTo1KgShipments() - halfTo1KgEliminateNum;
            scOutReturnSheet.setHalfTo1KgPolicyQualified(halfTo1KgPolicyQualified);
//0.5-1kg分档返利-金额
            scOutReturnSheet.setHalfTo1KgAmount(scOutReturnSheet.getHalfTo1KgRebateStandard().multiply(BigDecimal.valueOf(halfTo1KgPolicyQualified)));

//1-3kg分档返利-剔除票数
            Integer oneTo3KgEliminateNum = oneTo3KgEliminateNumMap.get(scOutReturnSheet.getName());
            if (oneTo3KgEliminateNum == null) {
                oneTo3KgEliminateNum = 0;
            }
            scOutReturnSheet.setOneTo3KgEliminateNum(oneTo3KgEliminateNum);
//1-3kg分档返利-符合政策票数
            Integer oneTo3KgPolicyQualified = scOutReturnSheet.getOneTo3KgShipments() - oneTo3KgEliminateNum;
            scOutReturnSheet.setOneTo3KgPolicyQualified(oneTo3KgPolicyQualified);
//1-3kg分档返利-金额
            scOutReturnSheet.setOneTo3KgAmount(scOutReturnSheet.getOneTo3KgRebateStandard().multiply(BigDecimal.valueOf(oneTo3KgPolicyQualified)));

//3-10kg分档返利-剔除票数
            Integer threeToTenKgEliminateNum = threeToTenKgEliminateNumMap.get(scOutReturnSheet.getName());
            if (threeToTenKgEliminateNum == null) {
                threeToTenKgEliminateNum = 0;
            }
            scOutReturnSheet.setThreeToTenKgEliminateNum(threeToTenKgEliminateNum);
//3-10kg分档返利-符合政策票数
            Integer threeToTenKgPolicyQualified = scOutReturnSheet.getThreeToTenKgShipments() - threeToTenKgEliminateNum;
            scOutReturnSheet.setThreeToTenKgPolicyQualified(threeToTenKgPolicyQualified);
//3-10kg分档返利-金额
            scOutReturnSheet.setThreeToTenKgAmount(scOutReturnSheet.getThreeToTenKgRebateStandard().multiply(BigDecimal.valueOf(threeToTenKgPolicyQualified)));

            BigDecimal totalRebateAmount = Optional.ofNullable(scOutReturnSheet.getZeroToHalfKgAmount())
                    .orElse(BigDecimal.ZERO)
                    .add(Optional.ofNullable(scOutReturnSheet.getHalfTo1KgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getOneTo3KgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getThreeToTenKgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getTenTo399KgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getIncrementalRebate0To1KgAmount())
                            .orElse(BigDecimal.ZERO))
                    .add(Optional.ofNullable(scOutReturnSheet.getCumulativeRebate0To2KgAmount())
                            .orElse(BigDecimal.ZERO));
            scOutReturnSheet.setTotalRebateAmount(totalRebateAmount);
            scOutReturnSheet.setTotalRebateAmount(totalRebateAmount);
            scOutReturnSheet.setSingleTicketRebate(totalRebateAmount.divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), mc));

            //一客一价返利
            //发件数
//    Integer oneToThreeKgRebateShipmentCountReceipt = scOutReturnSheetMapper.selectClientOneToThree(vo.getStartTime(), vo.getEndTime(), 1.0, 3.0);
//    scOutReturnSheet.setOneToThreeKgRebateShipmentCountReceipt(oneToThreeKgRebateShipmentCountReceipt);
            // 日业务量
//    Integer oneToThreeKgRebateDailyVolumeReceipt = scOutReturnSheetMapper.selectClientOneToThreeDaily();
//    scOutReturnSheet.setOneToThreeKgRebateDailyVolumeReceipt(oneToThreeKgRebateDailyVolumeReceipt);
            // 考核业务量
            // 剔除票数
            // 返利业务量
            if (scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == null || scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() == 0) {
                scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
            } else {
                Integer oneToThreeKgRebateRebateVolumeReceipt = scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() - scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt();
                if (oneToThreeKgRebateRebateVolumeReceipt > 0) {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
                } else {
                    scOutReturnSheet.setOneToThreeKgRebateRebateVolumeReceipt(0);
                }
            }
            //金额
            scOutReturnSheet.setOneToThreeKgRebateAmountReceipt(scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt())));

            //0-0.5kg超基数返利
            scOutReturnSheet.setZeroToHalfKgExceedBasePolicyQualified(scOutReturnSheet.getZeroToHalfKgPolicyQualified());
            //基数
            if (scOutReturnSheet.getName().equals("辽宁盘锦公司")) {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyBase(0);
            }
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() == 0) {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
            }

            Integer zeroToHalfKgExceedBasePolicyDifference = scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() - scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase();
            if (zeroToHalfKgExceedBasePolicyDifference > 0) {
                //scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(zeroToHalfKgExceedBasePolicyDifference);//修改前
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());//修改后
            } else {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(0);
            }
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyDifference(zeroToHalfKgExceedBasePolicyDifferenceMap.get(scOutReturnSheet.getName()));
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard() == null
                    || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().compareTo(BigDecimal.ZERO) == 0
                    || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() == null
                    || scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() == 0) {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(BigDecimal.valueOf(0));
            } else {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference())));
            }
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setZeroToHalfKgExceedBasePolicyRebate(zeroToHalfKgExceedBasePolicyRebateMap.get(scOutReturnSheet.getName()));
            }
            scOutReturnSheet.setZeroToHalfKgExceedBasePolicyGrossProfit(scOutReturnSheet.getZeroToHalfKgAmount().subtract(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate()));

//    0.5-1kg超基数返利
            scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(scOutReturnSheet.getHalfTo1KgPolicyQualified());
            scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(halfTo1KgExceedBasePolicyBaseMap.get(scOutReturnSheet.getName()));

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() == null) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyQualified(0);
            }
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() == null) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyBase(0);
            }
//    返利票数
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() == 0) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(0);
            }
            Integer halfTo1KgExceedBasePolicyDifference = scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() - scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase();
            if (halfTo1KgExceedBasePolicyDifference > 0) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified());
            } else {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(0);
            }
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyDifference(halfTo1KgExceedBasePolicyDifferenceMap.get(scOutReturnSheet.getName()));
            }
            scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference())));
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyRebate(halfTo1KgExceedBasePolicyRebateMap.get(scOutReturnSheet.getName()));
            }
            scOutReturnSheet.setHalfTo1KgExceedBasePolicyGrossProfit(scOutReturnSheet.getHalfTo1KgAmount().subtract(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate()));
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setHalfTo1KgExceedBasePolicyGrossProfit(halfTo1KgExceedBasePolicyGrossProfitMap.get(scOutReturnSheet.getName()));
            }
            //1-3分档返利
            scOutReturnSheet.setOneTo3KgRebatePolicyQualified(scOutReturnSheet.getOneTo3KgPolicyQualified());
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setOneTo3KgRebatePolicyQualified(oneTo3KgRebatePolicyQualifiedMap.get(scOutReturnSheet.getName()));
            }
            scOutReturnSheet.setOneTo3KgRebatePolicyRebate(scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneTo3KgRebatePolicyQualified())));
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setOneTo3KgRebatePolicyRebate(oneTo3KgRebatePolicyRebateMap.get(scOutReturnSheet.getName()));
            }
            //1-3kg分档返利-毛利
            scOutReturnSheet.setOneTo3KgRebatePolicyGrossProfit(scOutReturnSheet.getOneTo3KgAmount().subtract(scOutReturnSheet.getOneTo3KgRebatePolicyRebate()));
            if (vo.getNetworkLevel() == 1) {
                scOutReturnSheet.setOneTo3KgRebatePolicyGrossProfit(oneTo3KgRebatePolicyGrossProfitMap.get(scOutReturnSheet.getName()));
            }
            //3-999分档返利
            scOutReturnSheet.setThreeTo999KgRebatePolicyRebate(scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getThreeTo999KgRebatePolicyQualified())));
//3-999kg分档返利-毛利
            scOutReturnSheet.setThreeTo999KgRebatePolicyGrossProfit(scOutReturnSheet.getThreeToTenKgAmount().subtract(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate()));
            //1-3叠加返利
            scOutReturnSheet.setOneToThreeKgAdditiveRebate(scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets())));
            BigDecimal xoverlayPolicyOneTo3KgAmount = scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount();
            BigDecimal oneToThreeKgAdditiveRebate = scOutReturnSheet.getOneToThreeKgAdditiveRebate();
            if (xoverlayPolicyOneTo3KgAmount != null && oneToThreeKgAdditiveRebate != null) {
                scOutReturnSheet.setOneToThreeKgAdditiveGrossProfit(xoverlayPolicyOneTo3KgAmount.subtract(oneToThreeKgAdditiveRebate));
            }

            if (scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit() == null) {
                scOutReturnSheet.setOneToThreeKgAdditiveGrossProfit(new BigDecimal(0.00));
            }

            //0-2叠加返利
            scOutReturnSheet.setZeroToTwoKgAdditiveRebate(scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets())));
            BigDecimal cumulativeRebate0To2KgAmount = scOutReturnSheet.getCumulativeRebate0To2KgAmount();
            BigDecimal zeroToTwoKgAdditiveRebate = scOutReturnSheet.getZeroToTwoKgAdditiveRebate();
            if (cumulativeRebate0To2KgAmount != null && zeroToTwoKgAdditiveRebate != null) {
                scOutReturnSheet.setZeroToTwoKgAdditiveGrossProfit(cumulativeRebate0To2KgAmount.subtract(zeroToTwoKgAdditiveRebate));
            }

            //1-3kg一客一价返利
            Integer oneToThreeKgRebateRebateVolume = scOutReturnSheet.getOneToThreeKgRebateShipmentCount() - scOutReturnSheet.getOneToThreeKgRebateDailyVolume();
            if (oneToThreeKgRebateRebateVolume > 0 && scOutReturnSheet.getOneToThreeKgRebateDailyVolume() != 0) {
                scOutReturnSheet.setOneToThreeKgRebateRebateVolume(scOutReturnSheet.getOneToThreeKgRebateShipmentCount());
            } else {
                scOutReturnSheet.setOneToThreeKgRebateRebateVolume(0);
            }
            scOutReturnSheet.setOneToThreeKgRebateRebate(scOutReturnSheet.getOneToThreeKgRebateRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheet.getOneToThreeKgRebateRebateVolume())));
            scOutReturnSheet.setOneToThreeKgRebateGrossProfit(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().subtract(scOutReturnSheet.getOneToThreeKgRebateRebate()));

            //总部净返利合计
            BigDecimal headquartersNetRebateTotal = new BigDecimal(0.00);
            if (scOutReturnSheet.getTotalRebateAmount() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getTotalRebateAmount());
            }
            if (scOutReturnSheet.getExclusionAdjustment() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getExclusionAdjustment());
            }
            if (scOutReturnSheet.getOneToThreeKgRebateAmountReceipt() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt());
            }
            scOutReturnSheet.setHeadquartersNetRebateTotal(headquartersNetRebateTotal);

            //支付承包区返利合计
            BigDecimal paymentContractAreaRebateTotal = new BigDecimal(0.00);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate());
            }
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate());
            }
            if (scOutReturnSheet.getOneTo3KgRebatePolicyRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneTo3KgRebatePolicyRebate());
            }
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate());
            }
            if (scOutReturnSheet.getOneToThreeKgAdditiveRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgAdditiveRebate());
            }
            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getZeroToTwoKgAdditiveRebate());
            }
            if (scOutReturnSheet.getOneToThreeKgRebateRebate() != null) {
                paymentContractAreaRebateTotal = paymentContractAreaRebateTotal.add(scOutReturnSheet.getOneToThreeKgRebateRebate());
            }
            scOutReturnSheet.setPaymentContractAreaRebateTotal(paymentContractAreaRebateTotal);
            if (vo.getNetworkLevel() == 1) {
                System.out.println("承包区:" + scOutReturnSheet.getName() + " == 返利票数: " + paymentContractAreaRebateTotalMap.get(scOutReturnSheet.getName()));
                scOutReturnSheet.setPaymentContractAreaRebateTotal(paymentContractAreaRebateTotalMap.get(scOutReturnSheet.getName()));
            }
            //应付承包区金额-单票返利
            scOutReturnSheet.setSingleTicketRebateTotal(scOutReturnSheet.getPaymentContractAreaRebateTotal().divide(BigDecimal.valueOf(scOutReturnSheet.getTotalShipments()), 3));
            //返利毛利
            scOutReturnSheet.setRebateGrossProfit(scOutReturnSheet.getHeadquartersNetRebateTotal().subtract(scOutReturnSheet.getPaymentContractAreaRebateTotal()));


            int threeTo999 = scOutReturnSheet.getThreeToTenKgShipments() + scOutReturnSheet.getTenTo399KgShipments();
            scOutReturnSheet.setThreeTo999KgRebatePolicyQualified(threeTo999);
            /*scOutReturnSheet.setThreeTo999KgRebatePolicyQualified(scOutReturnSheet.getThreeToTenKgPolicyQualified() + scOutReturnSheet.getTenTo399KgShipments());*/
            scOutReturnSheet.setOneToThreeKgAdditiveRebateCompliantTickets(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard());
            scOutReturnSheet.setZeroToTwoKgAdditiveRebateCompliantTickets(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets());

        }
        return collect;
    }

    private int calculateDaysBetween(String startTime, String endTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate startDate = LocalDate.parse(startTime, formatter);
        LocalDate endDate = LocalDate.parse(endTime, formatter);
        return (int) ChronoUnit.DAYS.between(startDate, endDate);
    }

    @Override
    public List<ScOutReturnSheet> collectList(ScOutReturnSheetVo vo, OutputStream outputStream) {
        List<ScOutReturnSheet> collect = collectExport(vo);
        Workbook workbook = new XSSFWorkbook(); // 创建一个新的Excel工作簿
        Sheet sheet = workbook.createSheet("Amount Data"); // 创建一个新的工作表
        String[] cellName = {
                "日期",
                "名称",
                "0-0.5kg分档返利-发件数",
                "0-0.5kg分档返利-占比",
                "0-0.5kg分档返利-剔除票数",
                "0-0.5kg分档返利-符合政策票数",
                "0-0.5kg分档返利-返利标准",
                "0-0.5kg分档返利-金额",
                "0.5-1kg分档返利-发件数",
                "0.5-1kg分档返利-占比",
                "0.5-1kg分档返利-剔除票数",
                "0.5-1kg分档返利-符合政策票数",
                "0.5-1kg分档返利-返利标准",
                "0.5-1kg分档返利-金额",
                "1-3kg分档返利-发件数",
                "1-3kg分档返利-发件数",
                "1-3kg分档返利-剔除票数",
                "1-3kg分档返利-符合政策票数",
                "1-3kg分档返利-返利标准",
                "1-3kg分档返利-金额",
                "3-10kg分档返利-发件数",
                "3-10kg分档返利-占比",
                "3-10kg分档返利-剔除票数",
                "3-10kg分档返利-符合政策票数",
                "3-10kg分档返利-返利标准",
                "3-10kg分档返利-金额",
                "10-399kg分档返利-发件数",
                "10-399kg分档返利-占比",
                "10-399kg分档返利-返利标准",
                "10-399kg分档返利-金额",
                "叠加返利1-3kg-发件数",
                "叠加返利1-3kg-日基数",
                "叠加返利1-3kg-剔除票数",
                "叠加返利1-3kg-符合政策票数",
                "叠加返利1-3kg-返利标准",
                "叠加返利1-3kg-金额",
                "增量返利0-1kg-发件数",
                "增量返利0-1kg-日基数",
                "增量返利0-1kg-剔除票数",
                "增量返利0-1kg-符合政策票数",
                "增量返利0-1kg-返利标准",
                "增量返利0-1kg-金额",
                "0-2kg叠加返利-发件数",
                "0-2kg叠加返利-日基数",
                "0-2kg叠加返利-剔除票数",
                "0-2kg叠加返利-符合政策票数",
                "0-2kg叠加返利-返利标准",
                "0-2kg叠加返利-金额",
                "0-1kg阶梯考核-发件数",
                "0-1kg阶梯考核-日业务量",
                "0-1kg阶梯考核-考核业务量",
                "0-1kg阶梯考核-不足业务量",
                "0-1kg阶梯考核-考核标准",
                "0-1kg阶梯考核-金额",
                "0-999kg散单考核-发件数",
                "0-999kg散单考核-日业务量",
                "0-999kg散单考核-考核业务量",
                "0-999kg散单考核-不足业务量",
                "0-999kg散单考核-考核标准",
                "0-999kg散单考核-金额",
                "0-999kg业务考核-发件数",
                "0-999kg业务考核-日业务量",
                "0-999kg业务考核-考核业务量",
                "0-999kg业务考核-不足业务量",
                "0-999kg业务考核-考核标准",
                "0-999kg业务考核-金额",
                "发件票数合计",
                "返利金额合计",
                "应收总部金额-单票返利",
                "剔除数调整",
                "应收总部金额-1-3kg一客一价返利-发件数",
                "应收总部金额-1-3kg一客一价返利-日业务量",
                "应收总部金额-1-3kg一客一价返利-考核业务量",
                "应收总部金额-1-3kg一客一价返利-返利业务量",
                "应收总部金额-1-3kg一客一价返利-返利标准",
                "应收总部金额-1-3kg一客一价返利-一客一价金额",
                "总部净返利合计",
                "0-0.5kg超基数返利-符合政策票",
                "0-0.5kg超基数返利-基数",
                "0-0.5kg超基数返利-返利票数",
                "0-0.5kg超基数返利-返利标准",
                "0-0.5kg超基数返利-返利",
                "0-0.5kg超基数返利-毛利",
                "0.5-1kg超基数返利-符合政策票",
                "0.5-1kg超基数返利-基数",
                "0.5-1kg超基数返利-差额",
                "0.5-1kg超基数返利-返利标准",
                "0.5-1kg超基数返利-返利",
                "0.5-1kg超基数返利-毛利",
                "1-3kg分档返利-符合政策票",
                "1-3kg分档返利-返利标准",
                "1-3kg分档返利-返利",
                "1-3kg分档返利-毛利",
                "3-999kg分档返利-符合政策票",
                "3-999kg分档返利-返利标准",
                "3-999kg分档返利-返利",
                "3-999kg分档返利-毛利",
                "1-3kg叠加返利-符合政策票数",
                "1-3kg叠加返利-返利标准",
                "1-3kg叠加返利-返利",
                "1-3kg叠加返利-毛利",
                "0-2kg叠加返利-符合政策票数",
                "0-2kg叠加返利-返利标准",
                "0-2kg叠加返利-返利",
                "0-2kg叠加返利-毛利",
                "应付承包区金额-1-3kg一客一价返利-发件数",
                "应付承包区金额-1-3kg一客一价返利-日业务量",
                "应付承包区金额-1-3kg一客一价返利-考核业务量",
                "应付承包区金额-1-3kg一客一价返利-返利业务量",
                "应付承包区金额-1-3kg一客一价返利-返利标准",
                "应付承包区金额-1-3kg一客一价返利-返利",
                "应付承包区金额-1-3kg一客一价返利-毛利",
                "支付承包区返利合计",
                "应付承包区金额",
                "返利毛利"
        };
        Row headerRow = sheet.createRow(0);
        for (int i = 0; i < cellName.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(cellName[i]);
        }
        int rowNum = 1; // 行索引从1开始（因为已经有表头行）
        for (ScOutReturnSheet scOutReturnSheet : collect) {
            Row dataRow = sheet.createRow(rowNum++);
            dataRow.createCell(0).setCellValue(scOutReturnSheet.getName());
            dataRow.createCell(1).setCellValue(scOutReturnSheet.getDate());
            dataRow.createCell(2).setCellValue(scOutReturnSheet.getZeroToHalfKgShipments());
            dataRow.createCell(3).setCellValue(scOutReturnSheet.getZeroToHalfKgPercentage().doubleValue());
            dataRow.createCell(4).setCellValue(scOutReturnSheet.getZeroToHalfKgEliminateNum());
            dataRow.createCell(5).setCellValue(scOutReturnSheet.getZeroToHalfKgPolicyQualified());
            dataRow.createCell(6).setCellValue(scOutReturnSheet.getZeroToHalfKgRebateStandard().doubleValue());
            dataRow.createCell(7).setCellValue(scOutReturnSheet.getZeroToHalfKgAmount().doubleValue());

            // 0.5-1kg分档返利相关数据
            dataRow.createCell(8).setCellValue(scOutReturnSheet.getHalfTo1KgShipments());
            dataRow.createCell(9).setCellValue(scOutReturnSheet.getHalfTo1KgPercentage().doubleValue());
            dataRow.createCell(10).setCellValue(scOutReturnSheet.getHalfTo1KgEliminateNum());
            dataRow.createCell(11).setCellValue(scOutReturnSheet.getHalfTo1KgPolicyQualified());
            dataRow.createCell(12).setCellValue(scOutReturnSheet.getHalfTo1KgRebateStandard().doubleValue());
            dataRow.createCell(13).setCellValue(scOutReturnSheet.getHalfTo1KgAmount().doubleValue());

            // 1-3kg分档返利相关数据
            dataRow.createCell(14).setCellValue(scOutReturnSheet.getOneTo3KgShipments());
            dataRow.createCell(15).setCellValue(scOutReturnSheet.getOneTo3KgPercentage().doubleValue());
            dataRow.createCell(16).setCellValue(scOutReturnSheet.getOneTo3KgEliminateNum());
            dataRow.createCell(17).setCellValue(scOutReturnSheet.getOneTo3KgPolicyQualified());
            dataRow.createCell(18).setCellValue(scOutReturnSheet.getOneTo3KgRebateStandard().doubleValue());
            dataRow.createCell(19).setCellValue(scOutReturnSheet.getOneTo3KgAmount().doubleValue());

            // 3-10kg分档返利相关数据
            dataRow.createCell(20).setCellValue(scOutReturnSheet.getThreeToTenKgShipments());
            dataRow.createCell(21).setCellValue(scOutReturnSheet.getThreeToTenKgPercentage().doubleValue());
            dataRow.createCell(22).setCellValue(scOutReturnSheet.getThreeToTenKgEliminateNum());
            dataRow.createCell(23).setCellValue(scOutReturnSheet.getThreeToTenKgPolicyQualified());
            dataRow.createCell(24).setCellValue(scOutReturnSheet.getThreeToTenKgRebateStandard().doubleValue());
            dataRow.createCell(25).setCellValue(scOutReturnSheet.getThreeToTenKgAmount().doubleValue());

            // 10-399kg分档返利相关数据
            dataRow.createCell(26).setCellValue(scOutReturnSheet.getTenTo399KgShipments());
            dataRow.createCell(27).setCellValue(scOutReturnSheet.getTenTo399KgPercentage().doubleValue());
            dataRow.createCell(28).setCellValue(scOutReturnSheet.getTenTo399KgRebateStandard().doubleValue());
            dataRow.createCell(29).setCellValue(scOutReturnSheet.getTenTo399KgAmount().doubleValue());

            // 叠加返利1-3kg相关数据
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments() != null) {
                dataRow.createCell(30).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments());
            }
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() != null) {
                dataRow.createCell(31).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgBase());
            }
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgPolicyQualified() != null) {
                dataRow.createCell(32).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgPolicyQualified());
            }
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard() != null) {
                dataRow.createCell(33).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard().doubleValue());
            }
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage() != null) {
                dataRow.createCell(34).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().doubleValue());
            }
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount() != null) {
                dataRow.createCell(35).setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount().doubleValue());
            }

            // 增量返利0-1kg相关数据
            dataRow.createCell(36).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgShipmentCount());
            dataRow.createCell(37).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis());
            dataRow.createCell(38).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgExcludeTickets());
            dataRow.createCell(39).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets());
            dataRow.createCell(40).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgRebateStandard().doubleValue());
            dataRow.createCell(41).setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgAmount().doubleValue());

            // 0-2kg叠加返利相关数据
            dataRow.createCell(42).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgShipmentCount());
            dataRow.createCell(43).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis());
            dataRow.createCell(44).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgExcludeTickets());
            dataRow.createCell(45).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets());
            dataRow.createCell(46).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgRebateStandard().doubleValue());
            dataRow.createCell(47).setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgAmount().doubleValue());

            // 0-1kg阶梯考核相关数据
            dataRow.createCell(48).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgShipmentCount());
            dataRow.createCell(49).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgDailyVolume());
            if (scOutReturnSheet.getTieredAssessment0To1KgAssessedVolume() != null) {
                dataRow.createCell(50).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAssessedVolume());
            }
            if (scOutReturnSheet.getTieredAssessment0To1KgInsufficientVolume() != null) {
                dataRow.createCell(51).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgInsufficientVolume());
            }

            if (scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard() != null) {
                dataRow.createCell(52).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard().doubleValue());
            }

            if (scOutReturnSheet.getTieredAssessment0To1KgAmount() != null) {
                dataRow.createCell(53).setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAmount().doubleValue());
            }
            //0-999散单

            if (scOutReturnSheet.getThrowawayAssessment0To999KgShipmentCount() != null) {
                dataRow.createCell(54).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgShipmentCount());
            }

            if (scOutReturnSheet.getThrowawayAssessment0To999KgDailyVolume() != null) {
                dataRow.createCell(55).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgDailyVolume());
            }

            if (scOutReturnSheet.getThrowawayAssessment0To999KgAssessedVolume() != null) {
                dataRow.createCell(56).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgAssessedVolume());
            }

            if (scOutReturnSheet.getThrowawayAssessment0To999KgInsufficientVolume() != null) {
                dataRow.createCell(57).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgInsufficientVolume());
            }

            if (scOutReturnSheet.getThrowawayAssessment0To999KgAssessmentStandard() != null) {
                dataRow.createCell(58).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgAssessmentStandard().doubleValue());
            }

            if (scOutReturnSheet.getThrowawayAssessment0To999KgAmount() != null) {
                dataRow.createCell(59).setCellValue(scOutReturnSheet.getThrowawayAssessment0To999KgAmount().doubleValue());
            }

            //0-999业务
            if (scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount() != null) {
                dataRow.createCell(60).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount());
            }

            if (scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume() != null) {
                dataRow.createCell(61).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume());
            }

            if (scOutReturnSheet.getBusinessAssessment0To999KgAssessedVolume() != null) {
                dataRow.createCell(62).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAssessedVolume());
            }

            if (scOutReturnSheet.getBusinessAssessment0To999KgInsufficientVolume() != null) {
                dataRow.createCell(63).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgInsufficientVolume());
            }

            if (scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard() != null) {
                dataRow.createCell(64).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard().doubleValue());
            }

            if (scOutReturnSheet.getBusinessAssessment0To999KgAmount() != null) {
                dataRow.createCell(65).setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAmount().doubleValue());
            }

            dataRow.createCell(66).setCellValue(scOutReturnSheet.getTotalShipments());

            if (scOutReturnSheet.getTotalRebateAmount() != null) {
                dataRow.createCell(67).setCellValue(scOutReturnSheet.getTotalRebateAmount().doubleValue());
            }

            if (scOutReturnSheet.getSingleTicketRebate() != null) {
                dataRow.createCell(68).setCellValue(scOutReturnSheet.getSingleTicketRebate().doubleValue());
            }

            if (scOutReturnSheet.getExclusionAdjustment() != null) {
                dataRow.createCell(69).setCellValue(scOutReturnSheet.getExclusionAdjustment().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() != null) {
                dataRow.createCell(70).setCellValue(scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() != null) {
                dataRow.createCell(71).setCellValue(scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateAssessedVolumeReceipt() != null) {
                /*dataRow.createCell(72).setCellValue(scOutReturnSheet.getOneToThreeKgRebateAssessedVolumeReceipt());*/
                dataRow.createCell(72).setCellValue(0);
            }

            if (scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt() != null) {
                dataRow.createCell(73).setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt() != null) {
                dataRow.createCell(74).setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateAmountReceipt() != null) {
                dataRow.createCell(75).setCellValue(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().doubleValue());
            }

            if (scOutReturnSheet.getHeadquartersNetRebateTotal() != null) {
                dataRow.createCell(76).setCellValue(scOutReturnSheet.getHeadquartersNetRebateTotal().doubleValue());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() != null) {
                dataRow.createCell(77).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase() != null) {
                dataRow.createCell(78).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() != null) {
                dataRow.createCell(79).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard() != null) {
                dataRow.createCell(80).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate() != null) {
                dataRow.createCell(81).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate().doubleValue());
            }

            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyGrossProfit() != null) {
                dataRow.createCell(82).setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() != null) {
                dataRow.createCell(83).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified());
            }

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() != null) {
                dataRow.createCell(84).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase());
            }

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference() != null) {
                dataRow.createCell(85).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference());
            }

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard() != null) {
                dataRow.createCell(86).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate() != null) {
                dataRow.createCell(87).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate().doubleValue());
            }
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyGrossProfit() != null) {
                dataRow.createCell(88).setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getOneTo3KgRebatePolicyQualified() != null) {
                dataRow.createCell(89).setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyQualified());
            }

            if (scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard() != null) {
                dataRow.createCell(90).setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getOneTo3KgRebatePolicyRebate() != null) {
                dataRow.createCell(91).setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyRebate().doubleValue());
            }

            if (scOutReturnSheet.getOneTo3KgRebatePolicyGrossProfit() != null) {
                dataRow.createCell(92).setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getThreeTo999KgRebatePolicyQualified() != null) {
                dataRow.createCell(93).setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyQualified());
            }

            if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard() != null) {
                dataRow.createCell(94).setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebate() != null) {
                dataRow.createCell(95).setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate().doubleValue());
            }
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyGrossProfit() != null) {
                dataRow.createCell(96).setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets() != null) {
                dataRow.createCell(97).setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets());
            }

            if (scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard() != null) {
                dataRow.createCell(98).setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgAdditiveRebate() != null) {
                dataRow.createCell(99).setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebate().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit() != null) {
                dataRow.createCell(100).setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets() != null) {
                dataRow.createCell(101).setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets());
            }

            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard() != null) {
                dataRow.createCell(102).setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebate() != null) {
                dataRow.createCell(103).setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebate().doubleValue());
            }

            if (scOutReturnSheet.getZeroToTwoKgAdditiveGrossProfit() != null) {
                dataRow.createCell(104).setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateShipmentCount() != null) {
                dataRow.createCell(105).setCellValue(scOutReturnSheet.getOneToThreeKgRebateShipmentCount());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateDailyVolume() != null) {
                dataRow.createCell(106).setCellValue(scOutReturnSheet.getOneToThreeKgRebateDailyVolume());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateAssessedVolume() != null) {
                /*dataRow.createCell(107).setCellValue(scOutReturnSheet.getOneToThreeKgRebateAssessedVolume());*/
                dataRow.createCell(107).setCellValue(0);
            }

            if (scOutReturnSheet.getOneToThreeKgRebateRebateVolume() != null) {
                dataRow.createCell(108).setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateVolume());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateRebateStandard() != null) {
                dataRow.createCell(109).setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateStandard().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateRebate() != null) {
                dataRow.createCell(110).setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebate().doubleValue());
            }

            if (scOutReturnSheet.getOneToThreeKgRebateGrossProfit() != null) {
                dataRow.createCell(111).setCellValue(scOutReturnSheet.getOneToThreeKgRebateGrossProfit().doubleValue());
            }

            if (scOutReturnSheet.getPaymentContractAreaRebateTotal() != null) {
                dataRow.createCell(112).setCellValue(scOutReturnSheet.getPaymentContractAreaRebateTotal().doubleValue());
            }

            if (scOutReturnSheet.getSingleTicketRebateTotal() != null) {
                dataRow.createCell(113).setCellValue(scOutReturnSheet.getSingleTicketRebateTotal().doubleValue());
            }

            if (scOutReturnSheet.getRebateGrossProfit() != null) {
                dataRow.createCell(114).setCellValue(scOutReturnSheet.getRebateGrossProfit().doubleValue());
            }
        }
        try {
            workbook.write(outputStream); // 将工作簿写入输出流
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            workbook.close(); // 关闭工作簿
        } catch (IOException e) {
            e.printStackTrace();
        }
        return collect;
    }

    public List<TableVo> getTableVo() {
        List<TableVo> first = new ArrayList<>();
        TableVo firstTableVo = new TableVo();
        firstTableVo.setFields("date");
        firstTableVo.setTranslate("日期");
        first.add(firstTableVo);

        firstTableVo = new TableVo();
        firstTableVo.setFields("name");
        firstTableVo.setTranslate("承包区名称");
        first.add(firstTableVo);

        firstTableVo = new TableVo();
        firstTableVo.setFields("shouldReceipt");
        firstTableVo.setTranslate("应收总部金额");
        List<TableVo> second = new ArrayList<>();
        TableVo secondTableVo = new TableVo();
        secondTableVo.setFields("zeroToHalfKg");
        secondTableVo.setTranslate("0-0.5kg分档返利");
        List<TableVo> third = new ArrayList<>();
        String[] zeroToHalfKg = {"zeroToHalfKgShipments", "zeroToHalfKgPercentage", "zeroToHalfKgEliminateNum",
                "zeroToHalfKgPolicyQualified", "zeroToHalfKgRebateStandard", "zeroToHalfKgAmount"};
        InitTableVo initTableVo = new InitTableVo();
        initTableVo.setFields(zeroToHalfKg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "zeroToHalfKgShipments":
                    tableVo.setIsPoint(1);
                    break;
                case "zeroToHalfKgEliminateNum":
                    tableVo.setIsPoint(2);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
//        firstTableVo.setSunList(second);
//        first.add(firstTableVo);


        secondTableVo = new TableVo();
        secondTableVo.setFields("halfTo1Kg");
        secondTableVo.setTranslate("0.5-1kg分档返利");
        third = new ArrayList<>();
        String[] halfTo1Kg = {"halfTo1KgShipments", "halfTo1KgPercentage", "halfTo1KgEliminateNum",
                "halfTo1KgPolicyQualified", "halfTo1KgRebateStandard", "halfTo1KgAmount"};
        initTableVo.setFields(halfTo1Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "halfTo1KgShipments":
                    tableVo.setIsPoint(3);
                    break;
                case "halfTo1KgEliminateNum":
                    tableVo.setIsPoint(4);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("oneTo3Kg");
        secondTableVo.setTranslate("1-3kg分档返利");
        third = new ArrayList<>();
        String[] oneTo3Kg = {"oneTo3KgShipments", "oneTo3KgPercentage", "oneTo3KgEliminateNum",
                "oneTo3KgPolicyQualified", "oneTo3KgRebateStandard", "oneTo3KgAmount"};
        initTableVo.setFields(oneTo3Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "oneTo3KgShipments":
                    tableVo.setIsPoint(5);
                    break;
                case "oneTo3KgEliminateNum":
                    tableVo.setIsPoint(6);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("threeToTenKg");
        secondTableVo.setTranslate("3-10kg分档返利");
        third = new ArrayList<>();
        String[] threeToTenKg = {"threeToTenKgShipments", "threeToTenKgPercentage", "threeToTenKgEliminateNum",
                "threeToTenKgPolicyQualified", "threeToTenKgRebateStandard", "threeToTenKgAmount"};
        initTableVo.setFields(threeToTenKg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "threeToTenKgShipments":
                    tableVo.setIsPoint(7);
                    break;
                case "threeToTenKgEliminateNum":
                    tableVo.setIsPoint(8);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("tenTo399Kg");
        secondTableVo.setTranslate("10-399kg分档返利");
        third = new ArrayList<>();
        String[] tenTo399Kg = {"tenTo399KgShipments", "tenTo399KgPercentage", "tenTo399KgRebateStandard",
                "tenTo399KgAmount"};
        initTableVo.setFields(tenTo399Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "tenTo399KgShipments":
                    tableVo.setIsPoint(9);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("xoverlayPolicyOneTo3Kg");
        secondTableVo.setTranslate("叠加返利1-3kg");
        third = new ArrayList<>();
        String[] xoverlayPolicyOneTo3Kg = {"xoverlayPolicyOneTo3KgShipments", "xoverlayPolicyOneTo3KgBase", "xoverlayPolicyOneTo3KgPolicyQualified",
                "xoverlayPolicyOneTo3KgRebateStandard", "xoverlayPolicyOneTo3KgPercentage", "xoverlayPolicyOneTo3KgAmount"};
        initTableVo.setFields(xoverlayPolicyOneTo3Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "xoverlayPolicyOneTo3KgShipments":
                    tableVo.setIsPoint(10);
                    break;
                case "xoverlayPolicyOneTo3KgPolicyQualified":
                    tableVo.setIsPoint(11);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("incrementalRebate0To1Kg");
        secondTableVo.setTranslate("增量返利0-1kg");
        third = new ArrayList<>();
        String[] incrementalRebate0To1Kg = {"incrementalRebate0To1KgShipmentCount", "incrementalRebate0To1KgDailyBasis", "incrementalRebate0To1KgExcludeTickets",
                "incrementalRebate0To1KgPolicyCompliantTickets", "incrementalRebate0To1KgRebateStandard", "incrementalRebate0To1KgAmount"};
        initTableVo.setFields(incrementalRebate0To1Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "incrementalRebate0To1KgShipmentCount":
                    tableVo.setIsPoint(12);
                    break;
                case "incrementalRebate0To1KgExcludeTickets":
                    tableVo.setIsPoint(13);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("cumulativeRebate0To2Kg");
        secondTableVo.setTranslate("0-2kg叠加返利");
        third = new ArrayList<>();
        String[] cumulativeRebate0To2Kg = {"cumulativeRebate0To2KgShipmentCount", "cumulativeRebate0To2KgDailyBasis", "cumulativeRebate0To2KgExcludeTickets",
                "cumulativeRebate0To2KgPolicyCompliantTickets", "cumulativeRebate0To2KgRebateStandard", "cumulativeRebate0To2KgAmount"};
        initTableVo.setFields(cumulativeRebate0To2Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "cumulativeRebate0To2KgShipmentCount":
                    tableVo.setIsPoint(14);
                    break;
                case "cumulativeRebate0To2KgExcludeTickets":
                    tableVo.setIsPoint(15);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("tieredAssessment0To1Kg");
        secondTableVo.setTranslate("0-1kg阶梯考核");
        third = new ArrayList<>();
        String[] tieredAssessment0To1Kg = {"tieredAssessment0To1KgShipmentCount", "tieredAssessment0To1KgDailyVolume", "tieredAssessment0To1KgAssessedVolume",
                "tieredAssessment0To1KgInsufficientVolume", "tieredAssessment0To1KgAssessmentStandard", "tieredAssessment0To1KgAmount"};
        initTableVo.setFields(tieredAssessment0To1Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "tieredAssessment0To1KgShipmentCount":
                    tableVo.setIsPoint(16);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("throwawayAssessment0To999Kg");
        secondTableVo.setTranslate("0-999kg散单考核");
        third = new ArrayList<>();
        String[] throwawayAssessment0To999Kg = {"throwawayAssessment0To999KgShipmentCount", "throwawayAssessment0To999KgDailyVolume", "throwawayAssessment0To999KgAssessedVolume",
                "throwawayAssessment0To999KgInsufficientVolume", "throwawayAssessment0To999KgAssessmentStandard", "throwawayAssessment0To999KgAmount"};
        initTableVo.setFields(throwawayAssessment0To999Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        /*for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "throwawayAssessment0To999KgShipmentCount":
                    tableVo.setIsPoint(17);
                    break;
            }
        }*/
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("businessAssessment0To999Kg");
        secondTableVo.setTranslate("0-999kg业务考核");
        third = new ArrayList<>();
        String[] businessAssessment0To999Kg = {"businessAssessment0To999KgShipmentCount", "businessAssessment0To999KgDailyVolume", "businessAssessment0To999KgAssessedVolume",
                "businessAssessment0To999KgInsufficientVolume", "businessAssessment0To999KgAssessmentStandard", "businessAssessment0To999KgAmount"};
        initTableVo.setFields(businessAssessment0To999Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "businessAssessment0To999KgShipmentCount":
                    tableVo.setIsPoint(17);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("totalShipments");
        secondTableVo.setTranslate("发件票数合计");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("totalRebateAmount");
        secondTableVo.setTranslate("返利金额合计");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("singleTicketRebate");
        secondTableVo.setTranslate("单票返利");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("exclusionAdjustment");
        secondTableVo.setTranslate("剔除数调整");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("oneToThreeKgRebateReceipt");
        secondTableVo.setTranslate("1-3kg一客一价返利");
        third = new ArrayList<>();
        String[] oneToThreeKgRebateReceipt = {"oneToThreeKgRebateShipmentCountReceipt", "oneToThreeKgRebateDailyVolumeReceipt", /*"oneToThreeKgRebateAssessedVolumeReceipt",*/
                "oneToThreeKgRebateRebateVolumeReceipt", "oneToThreeKgRebateRebateStandardReceipt", "oneToThreeKgRebateAmountReceipt"};
        initTableVo.setFields(oneToThreeKgRebateReceipt);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            String fields = tableVo.getFields();
            switch (fields) {
                case "oneToThreeKgRebateShipmentCountReceipt":
                    tableVo.setIsPoint(18);
                    break;
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("headquartersNetRebateTotal");
        secondTableVo.setTranslate("总部净返利合计");
        second.add(secondTableVo);
//        first.add(firstTableVo);


        firstTableVo = new TableVo();
        firstTableVo.setFields("shouldPay");
        firstTableVo.setTranslate("应付承包区金额");
        secondTableVo = new TableVo();
        secondTableVo.setFields("zeroToHalfKgExceed");
        secondTableVo.setTranslate("0-0.5kg超基数返利");
        third = new ArrayList<>();
        String[] zeroToHalfKgExceed = {"zeroToHalfKgExceedBasePolicyQualified", "zeroToHalfKgExceedBasePolicyBase", "zeroToHalfKgExceedBasePolicyDifference",
                "zeroToHalfKgExceedBasePolicyRebateStandard", "zeroToHalfKgExceedBasePolicyRebate", "zeroToHalfKgExceedBasePolicyGrossProfit"};
        initTableVo.setFields(zeroToHalfKgExceed);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("halfTo1KgExceed");
        secondTableVo.setTranslate("0.5-1kg超基数返利");
        third = new ArrayList<>();
        String[] halfTo1KgExceed = {"halfTo1KgExceedBasePolicyQualified", "halfTo1KgExceedBasePolicyBase", "halfTo1KgExceedBasePolicyDifference",
                "halfTo1KgExceedBasePolicyRebateStandard", "halfTo1KgExceedBasePolicyRebate", "halfTo1KgExceedBasePolicyGrossProfit"};
        initTableVo.setFields(halfTo1KgExceed);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("oneTo3KgRebate");
        secondTableVo.setTranslate("1-3kg分档返利");
        third = new ArrayList<>();
        String[] oneTo3KgRebate = {"oneTo3KgRebatePolicyQualified", "oneTo3KgRebatePolicyRebateStandard", "oneTo3KgRebatePolicyRebate",
                "oneTo3KgRebatePolicyGrossProfit"};
        initTableVo.setFields(oneTo3KgRebate);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("threeTo999Kg");
        secondTableVo.setTranslate("3-999kg分档返利");
        third = new ArrayList<>();
        String[] threeTo999Kg = {"threeTo999KgRebatePolicyQualified", "threeTo999KgRebatePolicyRebateStandard", "threeTo999KgRebatePolicyRebate",
                "threeTo999KgRebatePolicyGrossProfit"};
        initTableVo.setFields(threeTo999Kg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("oneToThreeKgAdd");
        secondTableVo.setTranslate("1-3kg叠加返利");
        third = new ArrayList<>();
        String[] oneToThreeKgAdd = {"oneToThreeKgAdditiveRebateCompliantTickets", "oneToThreeKgAdditiveRebateStandard", "oneToThreeKgAdditiveRebate",
                "oneToThreeKgAdditiveGrossProfit"};
        initTableVo.setFields(oneToThreeKgAdd);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("zeroToTwoKgAdd");
        secondTableVo.setTranslate("0-2kg叠加返利");
        third = new ArrayList<>();
        String[] zeroToTwoKgAdd = {"zeroToTwoKgAdditiveRebateCompliantTickets", "zeroToTwoKgAdditiveRebateStandard", "zeroToTwoKgAdditiveRebate",
                "zeroToTwoKgAdditiveGrossProfit"};
        initTableVo.setFields(zeroToTwoKgAdd);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("oneToThreeKg");
        secondTableVo.setTranslate("1-3kg一客一价返利");
        third = new ArrayList<>();
        //oneToThreeKgRebateDailyVolumeReceipt
        String[] oneToThreeKg = {"oneToThreeKgRebateShipmentCount", "oneToThreeKgRebateDailyVolume", /*"oneToThreeKgRebateAssessedVolume",*/
                "oneToThreeKgRebateRebateVolume", "oneToThreeKgRebateRebateStandard", "oneToThreeKgRebateRebate", "oneToThreeKgRebateGrossProfit"};
        initTableVo.setFields(oneToThreeKg);
        initTableVo.setCode("scOutReturn");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("paymentContractAreaRebateTotal");
        secondTableVo.setTranslate("支付承包区返利合计");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("singleTicketRebateTotal");
        secondTableVo.setTranslate("应付承包区金额-单票返利");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("rebateGrossProfit");
        secondTableVo.setTranslate("返利毛利");
        second.add(secondTableVo);


        return first;
    }

    @Override
    public ScOutBoundReturnSheetSet select() {
        return scOutBoundReturnSheetSetMapper.select();
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"zeroToZeroPointFiveStandard", "zeroPointFiveToOneStandard", "oneToThreeStandard", "threeToTenStandard", "moreThanTenStandard", "oneToThreeOverlayStandardReceipt"
                , "oneToThreeOverlayNumReceipt", "zeroToOneAddStandard", "zeroToOneAddNum", "zeroToTwoOverlayStandardReceipt", "zeroToOneLadderStandardReceipt", "zeroToOneLadderNumReceipt"
                , "allThrowawayExamineStandard", "allBusinessExamineStandard", "allThrowawayExamineNum", "allBusinessExamineNum", "rejectionNumber", "oneClientOnePriceStandardReceipt", "oneClientOnePriceNumReceipt", "zeroToZeroPointFiveSuperStandard", "zeroToZeroPointFiveSuperNum", "zeroPointFiveToOneSuperStandard"
                , "oneToThreeSplitStandard", "moreThanThreeSplitStandard", "oneToThreeOverlayStandardPay", "zeroToTwoOverlayStandardPay", "oneClientOnePriceStandardPay", "oneClientOnePriceNumPay"};
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(ScOutBoundReturnSheetSetEnum.getValue(vo.getFields()));
        }
        return list;
    }

    @Override
    public List<HqNetworkBillDetail> point(ScOutReturnSheetPointVo vo) {
        PageHelper.startPage(vo.getPageDate());
        return hqNetworkBillDetailMapper.scOutReturnSheetPoint(vo);
    }

    @Override
    public List<ScOutReturnSheetDetailVo> selectChildList(ScOutReturnSheetChildVo vo) {
        List<ScOutReturnSheetDetail> detailList = new ArrayList<>();
        List<ScOutReturnSheetDetailVo> detailListVo = new ArrayList<>();
        if (vo.getDate().contains("至")) {
            String[] dates = vo.getDate().split("至");
            vo.setStartTime(dates[0]);
            vo.setEndTime(dates[1]);
            detailList = detailMapper.selectChildren(vo);
            for (ScOutReturnSheetDetail scOutReturnSheetDetail : detailList) {
                ScOutReturnSheetDetailVo scOutReturnSheetDetailVo = new ScOutReturnSheetDetailVo();
                BeanUtils.copyProperties(scOutReturnSheetDetail, scOutReturnSheetDetailVo);
                HqClientRelation hqClientRelation = hqClientRelationMapper.selectBigClientByName(scOutReturnSheetDetail.getName());
                if (hqClientRelation != null) {
                    if (hqClientRelation.getLevel().equals("父客户")) {
                        scOutReturnSheetDetailVo.setHasChildren(true);
                    }
                }
                detailListVo.add(scOutReturnSheetDetailVo);
            }
        } else {
            if (vo.getNetworkLevel() == 2) {
                ScOutReturnSheetVo scOutReturnSheetVo = new ScOutReturnSheetVo();
                scOutReturnSheetVo.setParentName(vo.getName());
                scOutReturnSheetVo.setNetworkLevel(2);
                scOutReturnSheetVo.setStartTime(vo.getDate());
                scOutReturnSheetVo.setEndTime(vo.getDate());
                scOutReturnSheetVo.setId(vo.getId());
                detailList = detailMapper.selectChildList(scOutReturnSheetVo);
                for (ScOutReturnSheetDetail scOutReturnSheetDetail : detailList) {
                    ScOutReturnSheetDetailVo scOutReturnSheetDetailVo = new ScOutReturnSheetDetailVo();
                    BeanUtils.copyProperties(scOutReturnSheetDetail, scOutReturnSheetDetailVo);
                    scOutReturnSheetDetailVo.setHasChildren(false);
                    detailListVo.add(scOutReturnSheetDetailVo);
                }
            }
        }
        return detailListVo;
    }

    @Override
    public Boolean updateClient(ScOutReturnSheetClient scOutReturnSheetClient) {
        return scOutReturnSheetClientMapper.updateClient(scOutReturnSheetClient);
    }

    @Override
    public ScOutReturnSheetClient selectClientSet(Integer id) {
        return scOutReturnSheetClientMapper.selectClientSet(id);
    }


    @Override
    public boolean update(ScOutBoundReturnSheetSet sheetSet) {
        return scOutBoundReturnSheetSetMapper.update(sheetSet);
    }

    @Override
    @Async
    public R exportAsync(ScOutReturnSheetVo vo) {
        long startTime = System.currentTimeMillis();
        // 使用 UUID 生成唯一文件名
        String fileName = "出港返利毛利报表汇总" + startTime + ".xlsx";
        //String path = "D:\\ruoyi\\uploadPath\\download\\" + "出港返利毛利报表汇总" + startTime + ".xlsx";
        String path = "/home/ruoyi/uploadPath/download/" + "出港返利毛利报表汇总" + startTime + ".xlsx";
        String sheetName = "出港返利毛利报表客户汇总";
        HqExportInfo hqExportInfo = new HqExportInfo();
        hqExportInfo.setSheetName("出港返利毛利报表汇总" + startTime + ".xlsx");
        hqExportInfo.setType("下载中");
//    hqExportInfo.setCreateBy(SecurityUtils.getUserId());
        hqExportInfoMapper.insert(hqExportInfo);
        List<ScOutReturnSheetDetailVo> collectDetail = detailMapper.selectList(vo);
        List<ScOutReturnSheet> collect = new ArrayList<>();
        if (collectDetail == null || collectDetail.size() == 0) {
            collect = collectExport(vo);
        } else {
            for (ScOutReturnSheetDetailVo scOutReturnSheetDetail : collectDetail) {
                ScOutReturnSheet sc = new ScOutReturnSheet();
                BeanUtils.copyProperties(scOutReturnSheetDetail, sc);
                collect.add(sc);
            }
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        int dateDifference = 1;
        try {
            Date d1 = sdf.parse(vo.getStartTime());
            Date d2 = sdf.parse(vo.getEndTime());

            // 获取日历实例
            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(d1);
            cal2.setTime(d2);

            // 计算日期差
            long diffInMillis = Math.abs(cal2.getTimeInMillis() - cal1.getTimeInMillis());
            long diffInDays = diffInMillis / (24 * 60 * 60 * 1000);
            dateDifference = (int) (dateDifference + diffInDays);
            System.out.println("日期差为： " + diffInDays + " 天");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (ScOutReturnSheet scOutReturnSheetDetail : collect) {
            scOutReturnSheetDetail.setDate(vo.getStartTime() + "至" + vo.getEndTime());
            //缓存表设置增量返利0~1kg符合政策票数
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount() != null) {
                int incrementalRebate0To1KgPolicyCompliantTickets = scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount()
                        - scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis() * calculateDaysBetween(vo.getStartTime(), vo.getEndTime())
                        - scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets() - scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis();
                scOutReturnSheetDetail.setIncrementalRebate0To1KgPolicyCompliantTickets(incrementalRebate0To1KgPolicyCompliantTickets);
            }
            // 0-1阶梯考核
            //考核业务量
            Integer tieredAssessment0To1KgInsufficientVolume = scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume() - scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount();
            if (tieredAssessment0To1KgInsufficientVolume < 0) {
                scOutReturnSheetDetail.setTieredAssessment0To1KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setTieredAssessment0To1KgInsufficientVolume(0);
            }
            //0-999业务考核
            //不足业务量
            Integer businessAssessment0To999KgInsufficientVolume = scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume() - scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount();
            if (businessAssessment0To999KgInsufficientVolume < 0) {
                scOutReturnSheetDetail.setBusinessAssessment0To999KgInsufficientVolume(0);
                scOutReturnSheetDetail.setBusinessAssessment0To999KgAmount(new BigDecimal(0));
            }
//            if (vo.getNetworkLevel() == 2) {
//                List<ScOutReturnSheetDetail> children = scOutReturnSheetDetail.getChildren();
//                for (ScOutReturnSheetDetail child : children) {
//                    String name = child.getName();
//                    vo.setParentName(name);
//                    vo.setStartTime(child.getDate());
//                    vo.setEndTime(child.getDate());
//                    List<ScOutReturnSheetDetail> detailList = detailMapper.selectChildList(vo);
//                    child.setChildren(detailList);
//                }
//            }
            //增量返利0-1kg-金额
            int incrementalRebate0To1KgShipmentCount = 0;
            int incrementalRebate0To1KgDailyBasis = 0;
            int incrementalRebate0To1KgExcludeTickets = 0;
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount() != null) {
                incrementalRebate0To1KgShipmentCount = scOutReturnSheetDetail.getIncrementalRebate0To1KgShipmentCount();
            }
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis() != null) {
                incrementalRebate0To1KgDailyBasis = scOutReturnSheetDetail.getIncrementalRebate0To1KgDailyBasis();
            }
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets() != null) {
                incrementalRebate0To1KgExcludeTickets = scOutReturnSheetDetail.getIncrementalRebate0To1KgExcludeTickets();
            }
            int IncrementalRebate0To1KgPolicyCompliantTickets = incrementalRebate0To1KgShipmentCount - incrementalRebate0To1KgDailyBasis * dateDifference - incrementalRebate0To1KgExcludeTickets;
            scOutReturnSheetDetail.setIncrementalRebate0To1KgPolicyCompliantTickets(IncrementalRebate0To1KgPolicyCompliantTickets);
            if (scOutReturnSheetDetail.getIncrementalRebate0To1KgRebateStandard() != null) {
                scOutReturnSheetDetail.setIncrementalRebate0To1KgAmount(new BigDecimal(IncrementalRebate0To1KgPolicyCompliantTickets).multiply(scOutReturnSheetDetail.getIncrementalRebate0To1KgRebateStandard()).setScale(2, RoundingMode.HALF_UP));
            }
            //0-1kg阶梯考核-考核业务
            int tieredAssessment0To1KgAssessedVolume = 0, tieredAssessment0To1KgShipmentCount = 0;
            if (scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume() != null) {
                tieredAssessment0To1KgAssessedVolume = scOutReturnSheetDetail.getTieredAssessment0To1KgAssessedVolume();
            }
            if (scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount() != null) {
                tieredAssessment0To1KgShipmentCount = scOutReturnSheetDetail.getTieredAssessment0To1KgShipmentCount();
            }
            if (tieredAssessment0To1KgShipmentCount > tieredAssessment0To1KgAssessedVolume) {
                scOutReturnSheetDetail.setTieredAssessment0To1KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setTieredAssessment0To1KgInsufficientVolume(0);
            }
            //0-999业务考核
            int businessAssessment0To999KgAssessedVolume = 0, businessAssessment0To999KgShipmentCount = 0;
            if (scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume() != null) {
                businessAssessment0To999KgAssessedVolume = scOutReturnSheetDetail.getBusinessAssessment0To999KgAssessedVolume();
            }
            if (scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount() != null) {
                businessAssessment0To999KgShipmentCount = scOutReturnSheetDetail.getBusinessAssessment0To999KgShipmentCount();
            }
            if (businessAssessment0To999KgShipmentCount > businessAssessment0To999KgAssessedVolume) {
                scOutReturnSheetDetail.setBusinessAssessment0To999KgAmount(new BigDecimal(0));
                scOutReturnSheetDetail.setBusinessAssessment0To999KgInsufficientVolume(0);
            }
            scOutReturnSheetDetail.setOneToThreeKgRebateRebateVolume(scOutReturnSheetDetail.getOneToThreeKgRebateRebateVolumeReceipt());
            scOutReturnSheetDetail.setOneToThreeKgRebateRebateStandard(scOutReturnSheetDetail.getOneToThreeKgRebateRebateStandardReceipt());
            scOutReturnSheetDetail.setOneToThreeKgRebateRebate(scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt());
            BigDecimal add = scOutReturnSheetDetail.getZeroToHalfKgAmount()
                    .add(scOutReturnSheetDetail.getHalfTo1KgAmount()
                            .add(scOutReturnSheetDetail.getOneTo3KgAmount()
                                    .add(scOutReturnSheetDetail.getThreeToTenKgAmount()
                                            .add(scOutReturnSheetDetail.getTenTo399KgAmount()
                                                    .add(scOutReturnSheetDetail.getXoverlayPolicyOneTo3KgAmount()
                                                            .add(scOutReturnSheetDetail.getIncrementalRebate0To1KgAmount()
                                                                    .add(scOutReturnSheetDetail.getCumulativeRebate0To2KgAmount()
                                                                            .add(scOutReturnSheetDetail.getTieredAssessment0To1KgAmount()
                                                                                    .add(scOutReturnSheetDetail.getBusinessAssessment0To999KgAmount())))))))));

            scOutReturnSheetDetail.setTotalRebateAmount(add);

            //总部净返利合计
            BigDecimal headquartersNetRebateTotal = new BigDecimal(0.00);
            if (scOutReturnSheetDetail.getTotalRebateAmount() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getTotalRebateAmount());
            }
            if (scOutReturnSheetDetail.getExclusionAdjustment() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getExclusionAdjustment());
            }
            if (scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt() != null) {
                headquartersNetRebateTotal = headquartersNetRebateTotal.add(scOutReturnSheetDetail.getOneToThreeKgRebateAmountReceipt());
            }
            scOutReturnSheetDetail.setHeadquartersNetRebateTotal(headquartersNetRebateTotal);
        }

        if (vo.getNetworkLevel() == 0) {
            for (ScOutReturnSheet scOutReturnSheetDetail : collect) {
                //3-999分档返利
                scOutReturnSheetDetail.setThreeTo999KgRebatePolicyRebate(scOutReturnSheetDetail.getThreeTo999KgRebatePolicyRebateStandard().multiply(BigDecimal.valueOf(scOutReturnSheetDetail.getThreeTo999KgRebatePolicyQualified())));
            }
        }
        Workbook workbook = new XSSFWorkbook(); // 创建一个新的Excel工作簿
        // 创建边框样式
        CellStyle borderStyle = workbook.createCellStyle();
        BorderStyle thin = BorderStyle.THIN;
        short blackColorIndex = IndexedColors.BLACK.getIndex();
        borderStyle.setBorderTop(thin);
        borderStyle.setBorderBottom(thin);
        borderStyle.setBorderLeft(thin);
        borderStyle.setBorderRight(thin);
        borderStyle.setTopBorderColor(blackColorIndex);
        borderStyle.setBottomBorderColor(blackColorIndex);
        borderStyle.setLeftBorderColor(blackColorIndex);
        borderStyle.setRightBorderColor(blackColorIndex);

// 创建表头样式
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setBold(true);
        headerFont.setFontHeightInPoints((short) 14); // 设置字体大小
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直居中
        headerStyle.setBorderTop(thin);
        headerStyle.setBorderBottom(thin);
        headerStyle.setBorderLeft(thin);
        headerStyle.setBorderRight(thin);
        headerStyle.setTopBorderColor(blackColorIndex);
        headerStyle.setBottomBorderColor(blackColorIndex);
        headerStyle.setLeftBorderColor(blackColorIndex);
        headerStyle.setRightBorderColor(blackColorIndex);
        Sheet sheet = workbook.createSheet("Amount Data"); // 创建一个新的工作表
        String[] cellName = {
                "日期",
                "名称",
                "0-0.5kg分档返利-发件数",
                "0-0.5kg分档返利-占比",
                "0-0.5kg分档返利-剔除票数",
                "0-0.5kg分档返利-符合政策票数",
                "0-0.5kg分档返利-返利标准",
                "0-0.5kg分档返利-金额",
                "0.5-1kg分档返利-发件数",
                "0.5-1kg分档返利-占比",
                "0.5-1kg分档返利-剔除票数",
                "0.5-1kg分档返利-符合政策票数",
                "0.5-1kg分档返利-返利标准",
                "0.5-1kg分档返利-金额",
                "1-3kg分档返利-发件数",
                "1-3kg分档返利-发件数",
                "1-3kg分档返利-剔除票数",
                "1-3kg分档返利-符合政策票数",
                "1-3kg分档返利-返利标准",
                "1-3kg分档返利-金额",
                "3-10kg分档返利-发件数",
                "3-10kg分档返利-占比",
                "3-10kg分档返利-剔除票数",
                "3-10kg分档返利-符合政策票数",
                "3-10kg分档返利-返利标准",
                "3-10kg分档返利-金额",
                "10-399kg分档返利-发件数",
                "10-399kg分档返利-占比",
                "10-399kg分档返利-返利标准",
                "10-399kg分档返利-金额",
                "叠加返利1-3kg-发件数",
                "叠加返利1-3kg-日基数",
                "叠加返利1-3kg-剔除票数",
                "叠加返利1-3kg-符合政策票数",
                "叠加返利1-3kg-返利标准",
                "叠加返利1-3kg-金额",
                "增量返利0-1kg-发件数",
                "增量返利0-1kg-日基数",
                "增量返利0-1kg-剔除票数",
                "增量返利0-1kg-符合政策票数",
                "增量返利0-1kg-返利标准",
                "增量返利0-1kg-金额",
                "0-2kg叠加返利-发件数",
                "0-2kg叠加返利-日基数",
                "0-2kg叠加返利-剔除票数",
                "0-2kg叠加返利-符合政策票数",
                "0-2kg叠加返利-返利标准",
                "0-2kg叠加返利-金额",
                "0-1kg阶梯考核-发件数",
                "0-1kg阶梯考核-日业务量",
                "0-1kg阶梯考核-考核业务量",
                "0-1kg阶梯考核-不足业务量",
                "0-1kg阶梯考核-考核标准",
                "0-1kg阶梯考核-金额",
                "0-999kg业务考核-发件数",
                "0-999kg业务考核-日业务量",
                "0-999kg业务考核-考核业务量",
                "0-999kg业务考核-不足业务量",
                "0-999kg业务考核-考核标准",
                "0-999kg业务考核-金额",
                "发件票数合计",
                "返利金额合计",
                "应收总部金额-单票返利",
                "剔除数调整",
                "应收总部金额-1-3kg一客一价返利-发件数",
                "应收总部金额-1-3kg一客一价返利-日业务量",
                /*"应收总部金额-1-3kg一客一价返利-考核业务量",*/
                "应收总部金额-1-3kg一客一价返利-返利业务量",
                "应收总部金额-1-3kg一客一价返利-返利标准",
                "应收总部金额-1-3kg一客一价返利-一客一价金额",
                "总部净返利合计",
                "0-0.5kg超基数返利-符合政策票",
                "0-0.5kg超基数返利-基数",
                "0-0.5kg超基数返利-返利票数",
                "0-0.5kg超基数返利-返利标准",
                "0-0.5kg超基数返利-返利",
                "0-0.5kg超基数返利-毛利",
                "0.5-1kg超基数返利-符合政策票",
                "0.5-1kg超基数返利-基数",
                "0.5-1kg超基数返利-差额",
                "0.5-1kg超基数返利-返利标准",
                "0.5-1kg超基数返利-返利",
                "0.5-1kg超基数返利-毛利",
                "1-3kg分档返利-符合政策票",
                "1-3kg分档返利-返利标准",
                "1-3kg分档返利-返利",
                "1-3kg分档返利-毛利",
                "3-999kg分档返利-符合政策票",
                "3-999kg分档返利-返利标准",
                "3-999kg分档返利-返利",
                "3-999kg分档返利-毛利",
                "1-3kg叠加返利-符合政策票数",
                "1-3kg叠加返利-返利标准",
                "1-3kg叠加返利-返利",
                "1-3kg叠加返利-毛利",
                "0-2kg叠加返利-符合政策票数",
                "0-2kg叠加返利-返利标准",
                "0-2kg叠加返利-返利",
                "0-2kg叠加返利-毛利",
                "应付承包区金额-1-3kg一客一价返利-发件数",
                "应付承包区金额-1-3kg一客一价返利-日业务量",
                /*"应付承包区金额-1-3kg一客一价返利-考核业务量",*/
                "应付承包区金额-1-3kg一客一价返利-返利业务量",
                "应付承包区金额-1-3kg一客一价返利-返利标准",
                "应付承包区金额-1-3kg一客一价返利-返利",
                "应付承包区金额-1-3kg一客一价返利-毛利",
                "支付承包区返利合计",
                "应付承包区金额",
                "返利毛利"
        };
        Row headerRow = sheet.createRow(0);
        for (int i = 0; i < cellName.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(cellName[i]);
            cell.setCellStyle(headerStyle);
        }
        int rowNum = 1; // 行索引从1开始（因为已经有表头行）
        for (ScOutReturnSheet scOutReturnSheet : collect) {
            int c = 0;
            Row dataRow = sheet.createRow(rowNum++);
            Cell cell0 = dataRow.createCell(c++);
            cell0.setCellValue(scOutReturnSheet.getName());
            cell0.setCellStyle(borderStyle);

            Cell cell1 = dataRow.createCell(c++);
            cell1.setCellValue(scOutReturnSheet.getDate());
            cell1.setCellStyle(borderStyle);

            Cell cell2 = dataRow.createCell(c++);
            cell2.setCellValue(scOutReturnSheet.getZeroToHalfKgShipments());
            cell2.setCellStyle(borderStyle);

            Cell cell3 = dataRow.createCell(c++);
            cell3.setCellValue(scOutReturnSheet.getZeroToHalfKgPercentage().doubleValue());
            cell3.setCellStyle(borderStyle);

            Cell cell4 = dataRow.createCell(c++);
            cell4.setCellValue(scOutReturnSheet.getZeroToHalfKgEliminateNum());
            cell4.setCellStyle(borderStyle);

            Cell cell5 = dataRow.createCell(c++);
            cell5.setCellValue(scOutReturnSheet.getZeroToHalfKgPolicyQualified());
            cell5.setCellStyle(borderStyle);

            Cell cell6 = dataRow.createCell(c++);
            cell6.setCellValue(scOutReturnSheet.getZeroToHalfKgRebateStandard().doubleValue());
            cell6.setCellStyle(borderStyle);

            Cell cell7 = dataRow.createCell(c++);
            cell7.setCellValue(scOutReturnSheet.getZeroToHalfKgAmount().doubleValue());
            cell7.setCellStyle(borderStyle);

            // 0.5-1kg分档返利相关数据
            Cell cell8 = dataRow.createCell(c++);
            cell8.setCellValue(scOutReturnSheet.getHalfTo1KgShipments());
            cell8.setCellStyle(borderStyle);

            Cell cell9 = dataRow.createCell(c++);
            cell9.setCellValue(scOutReturnSheet.getHalfTo1KgPercentage().doubleValue());
            cell9.setCellStyle(borderStyle);

            Cell cell10 = dataRow.createCell(c++);
            cell10.setCellValue(scOutReturnSheet.getHalfTo1KgEliminateNum());
            cell10.setCellStyle(borderStyle);

            Cell cell11 = dataRow.createCell(c++);
            cell11.setCellValue(scOutReturnSheet.getHalfTo1KgPolicyQualified());
            cell11.setCellStyle(borderStyle);

            Cell cell12 = dataRow.createCell(c++);
            cell12.setCellValue(scOutReturnSheet.getHalfTo1KgRebateStandard().doubleValue());
            cell12.setCellStyle(borderStyle);

            Cell cell13 = dataRow.createCell(c++);
            cell13.setCellValue(scOutReturnSheet.getHalfTo1KgAmount().doubleValue());
            cell13.setCellStyle(borderStyle);

            // 1-3kg分档返利相关数据
            Cell cell14 = dataRow.createCell(c++);
            cell14.setCellValue(scOutReturnSheet.getOneTo3KgShipments());
            cell14.setCellStyle(borderStyle);

            Cell cell15 = dataRow.createCell(c++);
            cell15.setCellValue(scOutReturnSheet.getOneTo3KgPercentage().doubleValue());
            cell15.setCellStyle(borderStyle);

            Cell cell16 = dataRow.createCell(c++);
            cell16.setCellValue(scOutReturnSheet.getOneTo3KgEliminateNum());
            cell16.setCellStyle(borderStyle);

            Cell cell17 = dataRow.createCell(c++);
            cell17.setCellValue(scOutReturnSheet.getOneTo3KgPolicyQualified());
            cell17.setCellStyle(borderStyle);

            Cell cell18 = dataRow.createCell(c++);
            cell18.setCellValue(scOutReturnSheet.getOneTo3KgRebateStandard().doubleValue());
            cell18.setCellStyle(borderStyle);

            Cell cell19 = dataRow.createCell(c++);
            cell19.setCellValue(scOutReturnSheet.getOneTo3KgAmount().doubleValue());
            cell19.setCellStyle(borderStyle);

            // 3-10kg分档返利相关数据
            Cell cell20 = dataRow.createCell(c++);
            cell20.setCellValue(scOutReturnSheet.getThreeToTenKgShipments());
            cell20.setCellStyle(borderStyle);

            Cell cell21 = dataRow.createCell(c++);
            cell21.setCellValue(scOutReturnSheet.getThreeToTenKgPercentage().doubleValue());
            cell21.setCellStyle(borderStyle);

            Cell cell22 = dataRow.createCell(c++);
            cell22.setCellValue(scOutReturnSheet.getThreeToTenKgEliminateNum());
            cell22.setCellStyle(borderStyle);

            Cell cell23 = dataRow.createCell(c++);
            cell23.setCellValue(scOutReturnSheet.getThreeToTenKgPolicyQualified());
            cell23.setCellStyle(borderStyle);

            Cell cell24 = dataRow.createCell(c++);
            cell24.setCellValue(scOutReturnSheet.getThreeToTenKgRebateStandard().doubleValue());
            cell24.setCellStyle(borderStyle);

            Cell cell25 = dataRow.createCell(c++);
            cell25.setCellValue(scOutReturnSheet.getThreeToTenKgAmount().doubleValue());
            cell25.setCellStyle(borderStyle);

            // 10-399kg分档返利相关数据
            Cell cell26 = dataRow.createCell(c++);
            cell26.setCellValue(scOutReturnSheet.getTenTo399KgShipments());
            cell26.setCellStyle(borderStyle);

            Cell cell27 = dataRow.createCell(c++);
            cell27.setCellValue(scOutReturnSheet.getTenTo399KgPercentage().doubleValue());
            cell27.setCellStyle(borderStyle);

            Cell cell28 = dataRow.createCell(c++);
            cell28.setCellValue(scOutReturnSheet.getTenTo399KgRebateStandard().doubleValue());
            cell28.setCellStyle(borderStyle);

            Cell cell29 = dataRow.createCell(c++);
            cell29.setCellValue(scOutReturnSheet.getTenTo399KgAmount().doubleValue());
            cell29.setCellStyle(borderStyle);

            // 叠加返利1-3kg相关数据
            Cell cell30 = dataRow.createCell(c++);
            cell30.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments() != null) {
                cell30.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgShipments());
            }

            Cell cell31 = dataRow.createCell(c++);
            cell31.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgBase() != null) {
                cell31.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgBase());
            }

            Cell cell32 = dataRow.createCell(c++);
            cell32.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgPolicyQualified() != null) {
                cell32.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgPolicyQualified());
            }

            Cell cell33 = dataRow.createCell(c++);
            cell33.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard() != null) {
                cell33.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard().doubleValue());
            }

            Cell cell34 = dataRow.createCell(c++);
            cell34.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage() != null) {
                cell34.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgPercentage().doubleValue());
            }

            Cell cell35 = dataRow.createCell(c++);
            cell35.setCellStyle(borderStyle);
            if (scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount() != null) {
                cell35.setCellValue(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount().doubleValue());
            }

// 增量返利0-1kg相关数据
            Cell cell36 = dataRow.createCell(c++);
            cell36.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgShipmentCount() != null) {
                cell36.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgShipmentCount());
            }

            Cell cell37 = dataRow.createCell(c++);
            cell37.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis() != null) {
                cell37.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgDailyBasis());
            }

            Cell cell38 = dataRow.createCell(c++);
            cell38.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgExcludeTickets() != null) {
                cell38.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgExcludeTickets());
            }

            Cell cell39 = dataRow.createCell(c++);
            cell39.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets() != null) {
                cell39.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgPolicyCompliantTickets());
            }

            Cell cell40 = dataRow.createCell(c++);
            cell40.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgRebateStandard() != null) {
                cell40.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgRebateStandard().doubleValue());
            }

            Cell cell41 = dataRow.createCell(c++);
            cell41.setCellStyle(borderStyle);
            if (scOutReturnSheet.getIncrementalRebate0To1KgAmount() != null) {
                cell41.setCellValue(scOutReturnSheet.getIncrementalRebate0To1KgAmount().doubleValue());
            }

// 0-2kg叠加返利相关数据
            Cell cell42 = dataRow.createCell(c++);
            cell42.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgShipmentCount() != null) {
                cell42.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgShipmentCount());
            }

            Cell cell43 = dataRow.createCell(c++);
            cell43.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis() != null) {
                cell43.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgDailyBasis());
            }

            Cell cell44 = dataRow.createCell(c++);
            cell44.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgExcludeTickets() != null) {
                cell44.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgExcludeTickets());
            }

            Cell cell45 = dataRow.createCell(c++);
            cell45.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets() != null) {
                cell45.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgPolicyCompliantTickets());
            }

            Cell cell46 = dataRow.createCell(c++);
            cell46.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgRebateStandard() != null) {
                cell46.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgRebateStandard().doubleValue());
            }

            Cell cell47 = dataRow.createCell(c++);
            cell47.setCellStyle(borderStyle);
            if (scOutReturnSheet.getCumulativeRebate0To2KgAmount() != null) {
                cell47.setCellValue(scOutReturnSheet.getCumulativeRebate0To2KgAmount().doubleValue());
            }

// 0-1kg阶梯考核相关数据
            Cell cell48 = dataRow.createCell(c++);
            cell48.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgShipmentCount() != null) {
                cell48.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgShipmentCount());
            }

            Cell cell49 = dataRow.createCell(c++);
            cell49.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgDailyVolume() != null) {
                cell49.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgDailyVolume());
            }

            Cell cell50 = dataRow.createCell(c++);
            cell50.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgAssessedVolume() != null) {
                cell50.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAssessedVolume());
            }

            Cell cell51 = dataRow.createCell(c++);
            cell51.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgInsufficientVolume() != null) {
                cell51.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgInsufficientVolume());
            }

            Cell cell52 = dataRow.createCell(c++);
            cell52.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard() != null) {
                cell52.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAssessmentStandard().doubleValue());
            }

            Cell cell53 = dataRow.createCell(c++);
            cell53.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTieredAssessment0To1KgAmount() != null) {
                cell53.setCellValue(scOutReturnSheet.getTieredAssessment0To1KgAmount().doubleValue());
            }

            Cell cell54 = dataRow.createCell(c++);
            cell54.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount() != null) {
                cell54.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgShipmentCount());
            }

            Cell cell55 = dataRow.createCell(c++);
            cell55.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume() != null) {
                cell55.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgDailyVolume());
            }

            Cell cell56 = dataRow.createCell(c++);
            cell56.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgAssessedVolume() != null) {
                cell56.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAssessedVolume());
            }

            Cell cell57 = dataRow.createCell(c++);
            cell57.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgInsufficientVolume() != null) {
                cell57.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgInsufficientVolume());
            }

            Cell cell58 = dataRow.createCell(c++);
            cell58.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard() != null) {
                cell58.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAssessmentStandard().doubleValue());
            }

            Cell cell59 = dataRow.createCell(c++);
            cell59.setCellStyle(borderStyle);
            if (scOutReturnSheet.getBusinessAssessment0To999KgAmount() != null) {
                cell59.setCellValue(scOutReturnSheet.getBusinessAssessment0To999KgAmount().doubleValue());
            }

            Cell cell60 = dataRow.createCell(c++);
            cell60.setCellValue(scOutReturnSheet.getTotalShipments());
            cell60.setCellStyle(borderStyle);

            Cell cell61 = dataRow.createCell(c++);
            cell61.setCellStyle(borderStyle);
            if (scOutReturnSheet.getTotalRebateAmount() != null) {
                cell61.setCellValue(scOutReturnSheet.getTotalRebateAmount().doubleValue());
            }
            Cell cell62 = dataRow.createCell(c++);
            cell62.setCellStyle(borderStyle);
            if (scOutReturnSheet.getSingleTicketRebate() != null) {
                cell62.setCellValue(scOutReturnSheet.getSingleTicketRebate().doubleValue());
            }

            Cell cell63 = dataRow.createCell(c++);
            cell63.setCellStyle(borderStyle);
            if (scOutReturnSheet.getExclusionAdjustment() != null) {
                cell63.setCellValue(scOutReturnSheet.getExclusionAdjustment().doubleValue());
            }

            Cell cell64 = dataRow.createCell(c++);
            cell64.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt() != null) {
                cell64.setCellValue(scOutReturnSheet.getOneToThreeKgRebateShipmentCountReceipt());
            }
            Cell cell65 = dataRow.createCell(c++);
            cell65.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt() != null) {
                cell65.setCellValue(scOutReturnSheet.getOneToThreeKgRebateDailyVolumeReceipt());
            }

            /*Cell cell66 = dataRow.createCell(c++);
            cell66.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateAssessedVolumeReceipt() != null) {
                *//*cell66.setCellValue(scOutReturnSheet.getOneToThreeKgRebateAssessedVolumeReceipt());*//*
                cell66.setCellValue(0);
            }*/

            Cell cell67 = dataRow.createCell(c++);
            cell67.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt() != null) {
                cell67.setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateVolumeReceipt());
            }

            Cell cell68 = dataRow.createCell(c++);
            cell68.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt() != null) {
                cell68.setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateStandardReceipt().doubleValue());
            }

            Cell cell69 = dataRow.createCell(c++);
            cell69.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateAmountReceipt() != null) {
                cell69.setCellValue(scOutReturnSheet.getOneToThreeKgRebateAmountReceipt().doubleValue());
            }

            Cell cell70 = dataRow.createCell(c++);
            cell70.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHeadquartersNetRebateTotal() != null) {
                cell70.setCellValue(scOutReturnSheet.getHeadquartersNetRebateTotal().doubleValue());
            }

            Cell cell71 = dataRow.createCell(c++);
            cell71.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified() != null) {
                cell71.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyQualified());
            }

            Cell cell72 = dataRow.createCell(c++);
            cell72.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase() != null) {
                cell72.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyBase());
            }

            Cell cell73 = dataRow.createCell(c++);
            cell73.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference() != null) {
                cell73.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyDifference());
            }

            Cell cell74 = dataRow.createCell(c++);
            cell74.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard() != null) {
                cell74.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebateStandard().doubleValue());
            }

            Cell cell75 = dataRow.createCell(c++);
            cell75.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate() != null) {
                cell75.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyRebate().doubleValue());
            }

            Cell cell76 = dataRow.createCell(c++);
            cell76.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToHalfKgExceedBasePolicyGrossProfit() != null) {
                cell76.setCellValue(scOutReturnSheet.getZeroToHalfKgExceedBasePolicyGrossProfit().doubleValue());
            }

            Cell cell77 = dataRow.createCell(c++);
            cell77.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified() != null) {
                cell77.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyQualified());
            }

            Cell cell78 = dataRow.createCell(c++);
            cell78.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase() != null) {
                cell78.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyBase());
            }

            Cell cell79 = dataRow.createCell(c++);
            cell79.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference() != null) {
                cell79.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyDifference());
            }

            Cell cell80 = dataRow.createCell(c++);
            cell80.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard() != null) {
                cell80.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebateStandard().doubleValue());
            }

            Cell cell81 = dataRow.createCell(c++);
            cell81.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate() != null) {
                cell81.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyRebate().doubleValue());
            }

            Cell cell82 = dataRow.createCell(c++);
            cell82.setCellStyle(borderStyle);
            if (scOutReturnSheet.getHalfTo1KgExceedBasePolicyGrossProfit() != null) {
                cell82.setCellValue(scOutReturnSheet.getHalfTo1KgExceedBasePolicyGrossProfit().doubleValue());
            }

            Cell cell83 = dataRow.createCell(c++);
            cell83.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneTo3KgRebatePolicyQualified() != null) {
                cell83.setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyQualified());
            }

            Cell cell84 = dataRow.createCell(c++);
            cell84.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard() != null) {
                cell84.setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyRebateStandard().doubleValue());
            }

            Cell cell85 = dataRow.createCell(c++);
            cell85.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneTo3KgRebatePolicyRebate() != null) {
                cell85.setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyRebate().doubleValue());
            }

            Cell cell86 = dataRow.createCell(c++);
            cell86.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneTo3KgRebatePolicyGrossProfit() != null) {
                cell86.setCellValue(scOutReturnSheet.getOneTo3KgRebatePolicyGrossProfit().doubleValue());
            }

            Cell cell87 = dataRow.createCell(c++);
            cell87.setCellStyle(borderStyle);
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyQualified() != null) {
                cell87.setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyQualified());
            }

            Cell cell88 = dataRow.createCell(c++);
            cell88.setCellStyle(borderStyle);
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard() != null) {
                cell88.setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyRebateStandard().doubleValue());
            }

            Cell cell89 = dataRow.createCell(c++);
            cell89.setCellStyle(borderStyle);
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyRebate() != null) {
                cell89.setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyRebate().doubleValue());
            }

            Cell cell90 = dataRow.createCell(c++);
            cell90.setCellStyle(borderStyle);
            if (scOutReturnSheet.getThreeTo999KgRebatePolicyGrossProfit() != null) {
                cell90.setCellValue(scOutReturnSheet.getThreeTo999KgRebatePolicyGrossProfit().doubleValue());
            }

            Cell cell91 = dataRow.createCell(c++);
            cell91.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets() != null) {
                cell91.setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebateCompliantTickets());
            }

            Cell cell92 = dataRow.createCell(c++);
            cell92.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard() != null) {
                cell92.setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebateStandard().doubleValue());
            }

            Cell cell93 = dataRow.createCell(c++);
            cell93.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgAdditiveRebate() != null) {
                cell93.setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveRebate().doubleValue());
            }

            Cell cell94 = dataRow.createCell(c++);
            cell94.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit() != null) {
                cell94.setCellValue(scOutReturnSheet.getOneToThreeKgAdditiveGrossProfit().doubleValue());
            }

            Cell cell95 = dataRow.createCell(c++);
            cell95.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets() != null) {
                cell95.setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebateCompliantTickets());
            }

            Cell cell96 = dataRow.createCell(c++);
            cell96.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard() != null) {
                cell96.setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebateStandard().doubleValue());
            }

            Cell cell97 = dataRow.createCell(c++);
            cell97.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToTwoKgAdditiveRebate() != null) {
                cell97.setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveRebate().doubleValue());
            }

            Cell cell98 = dataRow.createCell(c++);
            cell98.setCellStyle(borderStyle);
            if (scOutReturnSheet.getZeroToTwoKgAdditiveGrossProfit() != null) {
                cell98.setCellValue(scOutReturnSheet.getZeroToTwoKgAdditiveGrossProfit().doubleValue());
            }

            Cell cell99 = dataRow.createCell(c++);
            cell99.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateShipmentCount() != null) {
                cell99.setCellValue(scOutReturnSheet.getOneToThreeKgRebateShipmentCount());
            }

            Cell cell100 = dataRow.createCell(c++);
            cell100.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateDailyVolume() != null) {
                cell100.setCellValue(scOutReturnSheet.getOneToThreeKgRebateDailyVolume());
            }

            /*Cell cell101 = dataRow.createCell(c++);
            cell101.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateAssessedVolume() != null) {
                *//*cell101.setCellValue(scOutReturnSheet.getOneToThreeKgRebateAssessedVolume());*//*
                cell101.setCellValue(0);
            }*/

            Cell cell102 = dataRow.createCell(c++);
            cell102.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateRebateVolume() != null) {
                cell102.setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateVolume());
            }

            Cell cell103 = dataRow.createCell(c++);
            cell103.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateRebateStandard() != null) {
                cell103.setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebateStandard().doubleValue());
            }

            Cell cell104 = dataRow.createCell(c++);
            cell104.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateRebate() != null) {
                cell104.setCellValue(scOutReturnSheet.getOneToThreeKgRebateRebate().doubleValue());
            }

            Cell cell105 = dataRow.createCell(c++);
            cell105.setCellStyle(borderStyle);
            if (scOutReturnSheet.getOneToThreeKgRebateGrossProfit() != null) {
                cell105.setCellValue(scOutReturnSheet.getOneToThreeKgRebateGrossProfit().doubleValue());
            }

            Cell cell106 = dataRow.createCell(c++);
            cell106.setCellStyle(borderStyle);
            if (scOutReturnSheet.getPaymentContractAreaRebateTotal() != null) {
                cell106.setCellValue(scOutReturnSheet.getPaymentContractAreaRebateTotal().doubleValue());
            }

            Cell cell107 = dataRow.createCell(c++);
            cell107.setCellStyle(borderStyle);
            if (scOutReturnSheet.getSingleTicketRebateTotal() != null) {
                cell107.setCellValue(scOutReturnSheet.getSingleTicketRebateTotal().doubleValue());
            }

            Cell cell108 = dataRow.createCell(c++);
            cell108.setCellStyle(borderStyle);
            if (scOutReturnSheet.getRebateGrossProfit() != null) {
                cell108.setCellValue(scOutReturnSheet.getRebateGrossProfit().doubleValue());
            }
        }
        System.out.println("查询数据的耗时:" + (System.currentTimeMillis() - startTime));

        // 写入 Excel 文件到临时目录
        EasyExcel.write(path, ScOutReturnSheet.class)
                .sheet(sheetName)
                .doWrite(collect);

        // 获取代码执行后的时间戳
        long endTime = System.currentTimeMillis();
        // 计算代码执行所需的毫秒数
        long executionTime = endTime - startTime;
        System.out.println("执行这段代码的耗时(毫秒)：" + executionTime);

        hqExportInfo.setType("已完成");
        hqExportInfo.setUrl(path);
        hqExportInfo.setId(hqExportInfoMapper.selectIdByName(hqExportInfo.getSheetName()));
        hqExportInfoMapper.update(hqExportInfo);

        // 返回文件信息给前端
        Map<String, Object> result = new HashMap<>();
        result.put("fileUrl", path);
        result.put("fileName", fileName);
        return R.ok(result);
    }

    @Override
    public R cache(DateStrVo dateStrVo) {
        Integer[] networkLevels = {2, 1, 0};
//        Integer[] settleStatus = {1,2,3};
//        for (Integer status : settleStatus) {
        List<String> days = GetDateStringUtils.getDateStr(dateStrVo.getStartDateStr(), dateStrVo.getEndDateStr());
        List<String> dateStrList = detailMapper.selectllDateStr();
        days.removeAll(dateStrList);

        for (String day : days) {
//            String time = day;
            for (Integer networkLevel : networkLevels) {
                ScOutReturnSheetVo scOutReturnSheetVo = new ScOutReturnSheetVo();
                scOutReturnSheetVo.setNetworkLevel(networkLevel);
                scOutReturnSheetVo.setEndTime(day);
                scOutReturnSheetVo.setStartTime(day);
                PageDate pageDate = new PageDate();
                pageDate.setPageSize(100000);
                pageDate.setPageNum(1);
                scOutReturnSheetVo.setPageDate(pageDate);
                List<ScOutReturnSheet> collect = collectExport(scOutReturnSheetVo);
                List<ScOutReturnSheetDetail> detailList = new ArrayList<>();
                for (ScOutReturnSheet scOutReturnSheet : collect) {
                    ScOutReturnSheetDetail scOutReturnSheetDetail = new ScOutReturnSheetDetail();
                    BeanUtils.copyProperties(scOutReturnSheet, scOutReturnSheetDetail);
                    scOutReturnSheetDetail.setXoverlayPolicyOneTo3KgRebateStandard(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard());
                    scOutReturnSheetDetail.setXoverlayPolicyOneTo3KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount());
                    scOutReturnSheetDetail.setNetworkLevel(String.valueOf(networkLevel));
                    detailList.add(scOutReturnSheetDetail);
                }
                if (detailList.size() != 0) {
                    detailMapper.insertList(detailList);
                } else {
                    ScOutReturnSheetDetail scOutReturnSheetDetail = new ScOutReturnSheetDetail();
                    scOutReturnSheetDetail.setNetworkLevel(String.valueOf(networkLevel));
                    scOutReturnSheetDetail.setDate(day);
                    detailMapper.insert(scOutReturnSheetDetail);
                }
            }
            System.out.println(day + "的数据缓存成功");
        }

//        }
        return R.ok("添加成功");
    }

    @Override
    public R cacheChild(DateStrVo dateStrVo) {
        Integer[] networkLevels = {2};
//        Integer[] settleStatus = {1,2,3};
//        for (Integer status : settleStatus) {
        List<String> days = GetDateStringUtils.getDateStr(dateStrVo.getStartDateStr(), dateStrVo.getEndDateStr());
//        List<String> dateStrList = detailMapper.selectllDateStr();
//        days.removeAll(dateStrList);

        for (String day : days) {
//            String time = day;
            for (Integer networkLevel : networkLevels) {
                ScOutReturnSheetVo scOutReturnSheetVo = new ScOutReturnSheetVo();
                scOutReturnSheetVo.setNetworkLevel(networkLevel);
                scOutReturnSheetVo.setEndTime(day);
                scOutReturnSheetVo.setStartTime(day);
                PageDate pageDate = new PageDate();
                pageDate.setPageSize(100000);
                pageDate.setPageNum(1);
                scOutReturnSheetVo.setPageDate(pageDate);
                List<ScOutReturnSheet> collect = collectChildExport(scOutReturnSheetVo);
                List<ScOutReturnSheetDetail> detailList = new ArrayList<>();
                for (ScOutReturnSheet scOutReturnSheet : collect) {
                    ScOutReturnSheetDetail scOutReturnSheetDetail = new ScOutReturnSheetDetail();
                    BeanUtils.copyProperties(scOutReturnSheet, scOutReturnSheetDetail);
                    HqClientRelation hqClientRelation = hqClientRelationMapper.selectClientByName(scOutReturnSheet.getName());
                    if (hqClientRelation != null) {
                        HqClientRelation byId = hqClientRelationMapper.findById(hqClientRelation.getParentId());
                        if (byId != null) {
                            scOutReturnSheetDetail.setParentName(byId.getClientName());
                        }
                    }
                    scOutReturnSheetDetail.setXoverlayPolicyOneTo3KgRebateStandard(scOutReturnSheet.getXoverlayPolicyOneTo3KgRebateStandard());
                    scOutReturnSheetDetail.setXoverlayPolicyOneTo3KgAmount(scOutReturnSheet.getXoverlayPolicyOneTo3KgAmount());
                    scOutReturnSheetDetail.setNetworkLevel(String.valueOf(networkLevel));
                    detailMapper.insertChild(scOutReturnSheetDetail);
                    detailList.add(scOutReturnSheetDetail);
                }
            }
            System.out.println(day + "的数据缓存成功");
        }

//        }
        return R.ok("添加成功");
    }
}
